注意要先有图片: 放在 css/icons/下
HTML代码:
<div class="ub ub-f1"> <input id="bz-0" type="hidden" value=""> <div class=" res-hui ub-img" id="bz-1" onclick="Fstar(this)"></div> <div class=" res-hui ub-img" id="bz-2" onclick="Fstar(this)"></div> <div class=" res-hui ub-img" id="bz-3" onclick="Fstar(this)"></div> <div class=" res-hui ub-img" id="bz-4" onclick="Fstar(this)"></div> <div class=" res-hui ub-img" id="bz-5" onclick="Fstar(this)"></div> </div>
JS代码:
//评星功能 function Fstar(obj){//点击星星发生的事件 var id = $(obj).attr("ID"); var bz = id.split("-")[0]; var num= parseInt(id.split("-")[1]); $("#"+bz+"-0").val(num);for(var i=0;i<6;i++){ if(i<=num){ $("#"+bz+"-"+i).css("background-image","url(‘css/icons/starY.png‘)");// }else{ $("#"+bz+"-"+i).css("background-image","url(‘css/icons/starN.png‘)"); } } }
CSS代码:
.res-hui{ background-image:url(‘icons/starN.png‘); width:1.3em; height:1.3em; }
时间: 2024-10-17 21:19:05