jquery模仿淘宝星星打分
今天做论坛页面有星星评分功能,以下是代码。用的时候引入jquery
<span>
<ul class="hs_df_xx">
<li><img src="images/6-3-2.png" alt=""></li>
<li><img src="images/6-3-2.png" alt=""></li>
<li><img src="images/6-3-2.png" alt=""></li>
<li><img src="images/6-3-2.png" alt=""></li>
<li><img src="images/6-3-2.png" alt=""></li>
</ul>
<input type="hidden" name="score" value="5">
</span>
<script>
$(function(){
$(".hs_df_xx li").click(function(){
var $ts = $(this);
// alert($ts);
var hscl = $ts.hasClass("flg");
//alert(hscl);
var index = $ts.index();
//alert(index);
if(hscl){
if(index === 0){
$(".hs_df_xx li").removeClass("flg").children("img").attr("src","images/6-3-2.png");
}else{
$(".hs_df_xx li:gt("+(index-1)+")").removeClass("flg").children("img").attr("src","images/6-3-2.png");
}
}else{
$(".hs_df_xx li:lt("+(index+1)+")").addClass("flg").children("img").attr("src","images/6-3.png");
}
$("input[name='score']").val(index+1);
});
});
//
</script>
具体的功能是这样的