.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("评分失败!");
}
});
});
});
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2899/viewspace-2813240/ ,如需转载,请注明出处,否则将追究法律责任。