jQuery可多次使用的星级插件

开发 前端
css代码从项目中分解出,有一小部分没贴完,大家可以根据自己的需求修改css style。

一个关于jquery***插件的博文,那是我从网上收集的,它只支持一个页面中使用一次,多次使用的话会发生冲突,达不到我项目的需求,没办法,只能修改它

效果图如下:

 

css所需背景图片:

二话不说,帖代码:

html代码

<div class="xing">   
<span style="float: left">总体评价:<font color="#CC3300" size="-1">*</font></span><div   
class="rating-wrap">   
<ul id="xing1">   
<li><a href="javascript:;" data-rate-value="10" data-hint="很差" title="很差" class="one-star">   
</a></li>   
<li><a href="javascript:;" data-rate-value="20" data-hint="差" title="差" class="two-stars ">   
</a></li>   
<li><a href="javascript:;" data-rate-value="30" data-hint="还行" title="还行" class="three-stars ">   
</a></li>   
<li><a href="javascript:;" data-rate-value="40" data-hint="好" title="好" class="four-stars">   
</a></li>   
<li><a href="javascript:;" data-rate-value="50" data-hint="很好" title="很好" class="five-stars">   
</a></li>   
</ul>   
</div>   
<span class="xing1">点击星星开始打分</span>   
</div>   
<divclassdivclass="xing">   
<span style="float: left">广告效果:<font color="#CC3300"size="-1">*</font></span><div   
class="rating-wrap">   
<ulidulid="xing2">   
<li><a href="javascript:;" data-rate-value="10" data-hint="很差" title="很差" class="one-star">   
</a></li>   
<li><a href="javascript:;" data-rate-value="20" data-hint="差" title="差" class="two-stars ">   
</a></li>   
<li><a href="javascript:;" data-rate-value="30" data-hint="还行" title="还行" class="three-stars ">   
</a></li>   
<li><a href="javascript:;" data-rate-value="40" data-hint="好" title="好" class="four-stars">   
</a></li>   
<li><a href="javascript:;" data-rate-value="50" data-hint="很好" title="很好" class="five-stars">   
</a></li>   
</ul>   
</div>   
<span class="xing2">点击星星开始打分</span>   
</div>  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.

JS代码

<script type="text/javascript" src="js/jQuery_1.42.js"></script>   
<script type="text/javascript">   
$(function(){   
$(".rating-wrap a").mouseover(function(){   
$(this).parent().siblings().find("a").removeClass("active-star");   
$(this).addClass("active-star");   
$("."+$(this).parent().parent().attr("id")).html($(this).attr("data-hint"))   
}).mouseleave(function(){   
var selectID=$(this).parent().parent().attr("id")+"select";   
$(this).removeClass("active-star");   
if($("#"+selectID).length==0)   
{   
$("."+$(this).parent().parent().attr("id")).removeClass("active-hint").html("点击星星开始打分");   
}   
else   
{   
$("."+$(this).parent().parent().attr("id")).html($("#"+selectID).attr("data-hint"));   
$("#"+selectID).addClass("active-star");   
}   
}).click(function(){   
$(this).addClass("active-star").attr('id',$(this).parent().parent().attr("id")+"select");   
$(this).parent().siblings().find("a").attr("id","");   
$("."+$(this).parent().parent().attr("id")).html($(this).attr("data-hint")).addClass("active-hint");   
})   
})   
</script>   
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

css代码

<style>   
.item-rank-rst, .user-rank-rst, .rating-wrap ul, .rating-wrap a:hover, .rating-wrap .active-star, .user-m-star, .urr-rank60, .breadcrumb .note {   
background-imageurl(xing_bg.png);/**-----***插件背景图片----**/   
background-repeatno-repeat;   
}   
.rating-wrap {   
backgroundnone repeat scroll 0 0 #FFF9F1;   
border1px solid #EFE0D7;   
display: inline-block;   
floatleft;   
height20px;   
margin-right5px;   
padding4px 0 0 5px;   
positionrelative;   
top: -2px;   
width89px;   
z-index0;   
}   
.rating-wrap ul {   
background-position0 -250px;   
height16px;   
positionrelative;   
width85px;   
z-index10;   
}   
.rating-wrap li {   
displayinline;   
}   
.rating-wrap a {   
displayblock;   
height16px;   
left: 0;   
positionabsolute;   
top: 0;   
}   
.rating-wrap .five-stars {   
background-position0 -160px;   
width84px;   
z-index10;   
}   
.rating-wrap .four-stars {   
background-position0 -178px;   
width68px;   
z-index20;   
}   
.rating-wrap .three-stars {   
background-position0 -196px;   
width51px;   
z-index30;   
}   
.rating-wrap .two-stars {   
background-position0 -214px;   
width34px;   
z-index40;   
}   
.rating-wrap .one-star {   
background-position0 -232px;   
width17px;   
z-index50;   
}   
.rating-block .hint {   
color#999999;   
floatleft;   
}   
.active-hint {   
color#CC0000;   
}   
.rating-block .err-hint {   
color#EE0000;   
font-weightbold;   
}   
</style>  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.

注:css代码从项目中分解出,有一小部分没贴完,大家可以根据自己的需求修改css style

责任编辑:张伟 来源: 脚本之家
相关推荐

2012-05-02 10:04:43

jQuery插件

2013-12-02 15:31:37

jQuery插件

2013-12-02 15:25:38

jQuery插件

2013-12-02 14:53:20

jQuery插件

2013-01-09 10:20:26

jQueryFlotjQuery插件

2012-05-10 13:45:45

jQuery

2009-06-26 16:12:08

ThickboxjQuery

2013-12-02 15:36:17

jQuery插件

2020-05-14 14:54:00

GitHub星级开源

2013-12-02 15:43:05

jQuery插件

2013-03-20 13:21:51

jQueryjQuery插件

2009-06-24 10:58:21

jQuery插件教程

2012-04-16 09:19:03

jQuery插件

2012-04-25 09:43:43

jQuery插件

2013-12-02 15:21:30

jQuery插件

2013-12-02 15:10:56

jQuery插件

2012-03-29 09:27:49

WEBjQuery

2012-07-16 14:32:03

jQuery

2011-08-01 08:51:12

jQuery Mobi插件

2013-10-09 10:00:35

JQueryJQuery插件
点赞
收藏

51CTO技术栈公众号