ITPub博客

首页 > IT职业 > IT生活 > jquery 评分

jquery 评分

IT生活 作者:qingcai 时间:2021-09-09 09:50:47 0 删除 编辑

jQuery评分

.starsBg{

     background:url("/App/Tpl/default/Admin/Public/images/start.gif") 0 -22px; top:0; left:0; height:22px; padding:0px; cursor:pointer;

    }

.starsovering{

    background:url("/App/Tpl/default/Admin/Public/images/start.gif"); height:22px; position:absolute; top:0; left:0;

}

.starsON{

     position:absolute; top:0; left:0;height:22px;

}

//jQuery.fn.extend(object) 扩展 jQuery 元素集来提供新的方法(通常用来制作插件)。

jQuery.fn.stars = function(options,callback){

    //默认设置

    var settings = { MaxStar:20,StarWidth:23,CurrentStar:5,Enabled:true};   

    if(options) {

        jQuery.extend(settings, options);

    };

    var container = jQuery(this);

    container.css({"position":"relative"})

    .html('

    ')   

        .find('.starsBg').width(settings.MaxStar*settings.StarWidth)

        .html('

  • ');

        if(settings.Enabled){

            var ListArray = "";   

            for(k=1;k

                ListArray +='

  • ';

            }

            container.find('.starsBg').append(ListArray)

            .find('.starsON').hover(

            function(){

                $("#starid").hide();

                $(this).removeClass('starsON').addClass("starsovering");

            },

            function(){

                $(this).removeClass('starsovering').addClass("starsON");

                $("#starid").show();

        })

        .click(function(){

            var star_count = settings.MaxStar - $(this).css("z-index")+1;

            $("#starid").width(star_count*settings.StarWidth)

            //回调函数

            if (typeof callback == 'function') {

                callback(star_count);

                return ;

            }

        })

        }

    }

            $(document).ready(function(){

                var star = {$vo.star};           $("#star").stars({MaxStar:5,CurrentStar:star,Enabled:true},function(value){

                    var postStar = value;

                    $.post("__URL__/starStatus","id="+$(".id").val()+"&star="+postStar,function(date) {

                        if (date == 1) {

                            alert("评分成功!");

                        }else {

                            alert("评分失败!");

                        }

                    });

                });

            });

        

    评分:

        

           

            

        

        

    备注:满分5颗星

  • 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2899/viewspace-2813240/ ,如需转载,请注明出处,否则将追究法律责任。

    请登录后发表评论 登录
    全部评论

    注册时间:2019-08-19

    • 博文量
      71
    • 访问量
      681