精炼的jquery评分代码

[html]
<html>
<head><title>JQuery星星评级</title><meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script>
<style type="text/css">
<!–
.star_rating {background:url(https://www.lvxinwei.com/wp-content/uploads/2012/03/114922_gGrF_101311.gif) -80px 0 no-repeat; padding:0;margin:0; width:80px; height:16px; float:left; position:relative; }
.star_rating li {padding:0;margin:0;float:left;width:16px;height:16px;}
–>
</style>
</head><body>
<div style="display:block; float:left;width:100px;"><span>*</span>&nbsp;总体评价:</div>
<ul class="star_rating"><li><li/><li><li/><li></li><li></li></ul>

<script type="text/javascript">
$(‘.star_rating li’).each(function(){
$(this).click(function(obj){
$(‘.star_rating li’).unbind();//移除事件绑定
var Too = (obj.srcElement.offsetLeft+16);
setStarPos(Too-80);
alert((Too/16)+’星’);
}).mouseover(function(obj){
setStarPos((obj.srcElement.offsetLeft+16)-80);
}).mouseout(function(obj){
setStarPos(‘-80’);
});
});
function setStarPos(le){
$(‘.star_rating’).css({‘backgroundPosition’:le+’px 0′});
};
</script></body></html>
[/html]

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据