jquery星級(jí)插件、支持頁面中多次使用
更新時(shí)間:2012年03月25日 21:16:55 作者:
一個(gè)關(guān)于jquery星級(jí)插件的博文,那是我從網(wǎng)上收集的,它只支持一個(gè)頁面中使用一次,多次使用的話會(huì)發(fā)生沖突,達(dá)不到我項(xiàng)目的需求,沒辦法,只能修改它
效果圖如下:

二話不說,帖代碼:
html代碼
<div class="xing">
<span style="float: left">總體評(píng)價(jià):<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">點(diǎn)擊星星開始打分</span>
</div>
<divclass="xing">
<span style="float: left">廣告效果:<font color="#CC3300"size="-1">*</font></span><div
class="rating-wrap">
<ulid="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">點(diǎn)擊星星開始打分</span>
</div>
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("點(diǎn)擊星星開始打分");
}
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>
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-image: url(xing_bg.png);/**-----星級(jí)插件背景圖片----**/
background-repeat: no-repeat;
}
.rating-wrap {
background: none repeat scroll 0 0 #FFF9F1;
border: 1px solid #EFE0D7;
display: inline-block;
float: left;
height: 20px;
margin-right: 5px;
padding: 4px 0 0 5px;
position: relative;
top: -2px;
width: 89px;
z-index: 0;
}
.rating-wrap ul {
background-position: 0 -250px;
height: 16px;
position: relative;
width: 85px;
z-index: 10;
}
.rating-wrap li {
display: inline;
}
.rating-wrap a {
display: block;
height: 16px;
left: 0;
position: absolute;
top: 0;
}
.rating-wrap .five-stars {
background-position: 0 -160px;
width: 84px;
z-index: 10;
}
.rating-wrap .four-stars {
background-position: 0 -178px;
width: 68px;
z-index: 20;
}
.rating-wrap .three-stars {
background-position: 0 -196px;
width: 51px;
z-index: 30;
}
.rating-wrap .two-stars {
background-position: 0 -214px;
width: 34px;
z-index: 40;
}
.rating-wrap .one-star {
background-position: 0 -232px;
width: 17px;
z-index: 50;
}
.rating-block .hint {
color: #999999;
float: left;
}
.active-hint {
color: #CC0000;
}
.rating-block .err-hint {
color: #EE0000;
font-weight: bold;
}
</style>
注:css代碼從項(xiàng)目中分解出,有一小部分沒貼完,大家可以根據(jù)自己的需求修改css style


二話不說,帖代碼:
html代碼
復(fù)制代碼 代碼如下:
<div class="xing">
<span style="float: left">總體評(píng)價(jià):<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">點(diǎn)擊星星開始打分</span>
</div>
<divclass="xing">
<span style="float: left">廣告效果:<font color="#CC3300"size="-1">*</font></span><div
class="rating-wrap">
<ulid="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">點(diǎn)擊星星開始打分</span>
</div>
JS代碼
復(fù)制代碼 代碼如下:
<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("點(diǎn)擊星星開始打分");
}
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>
css代碼
復(fù)制代碼 代碼如下:
<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-image: url(xing_bg.png);/**-----星級(jí)插件背景圖片----**/
background-repeat: no-repeat;
}
.rating-wrap {
background: none repeat scroll 0 0 #FFF9F1;
border: 1px solid #EFE0D7;
display: inline-block;
float: left;
height: 20px;
margin-right: 5px;
padding: 4px 0 0 5px;
position: relative;
top: -2px;
width: 89px;
z-index: 0;
}
.rating-wrap ul {
background-position: 0 -250px;
height: 16px;
position: relative;
width: 85px;
z-index: 10;
}
.rating-wrap li {
display: inline;
}
.rating-wrap a {
display: block;
height: 16px;
left: 0;
position: absolute;
top: 0;
}
.rating-wrap .five-stars {
background-position: 0 -160px;
width: 84px;
z-index: 10;
}
.rating-wrap .four-stars {
background-position: 0 -178px;
width: 68px;
z-index: 20;
}
.rating-wrap .three-stars {
background-position: 0 -196px;
width: 51px;
z-index: 30;
}
.rating-wrap .two-stars {
background-position: 0 -214px;
width: 34px;
z-index: 40;
}
.rating-wrap .one-star {
background-position: 0 -232px;
width: 17px;
z-index: 50;
}
.rating-block .hint {
color: #999999;
float: left;
}
.active-hint {
color: #CC0000;
}
.rating-block .err-hint {
color: #EE0000;
font-weight: bold;
}
</style>
注:css代碼從項(xiàng)目中分解出,有一小部分沒貼完,大家可以根據(jù)自己的需求修改css style
您可能感興趣的文章:
- jQuery Raty 一款不錯(cuò)的星級(jí)評(píng)分插件
- 如何實(shí)現(xiàn)星星評(píng)價(jià)(jquery.raty.js插件)
- 基于jQuery的星級(jí)評(píng)分插件
- jQuery滿意度星級(jí)評(píng)價(jià)插件特效代碼分享
- jquery插件star-rating.js實(shí)現(xiàn)星級(jí)評(píng)分特效
- jQuery插件-jRating評(píng)分插件源碼分析及使用方法
- jquery五角星評(píng)分插件示例分享
- jQuery超贊的評(píng)分插件(8款)
- jQuery Raty星級(jí)評(píng)分插件使用方法實(shí)例分析
相關(guān)文章
jQuery實(shí)現(xiàn)底部浮動(dòng)窗口效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)底部浮動(dòng)窗口效果,涉及jQuery事件響應(yīng)及頁面元素動(dòng)態(tài)變換的相關(guān)操作技巧,需要的朋友可以參考下2016-09-09
jquery幻燈片插件bxslider樣式改進(jìn)實(shí)例
這篇文章主要介紹了jquery幻燈片插件bxslider樣式改進(jìn),對(duì)比官方樣式以實(shí)例形式講述了改進(jìn)的技巧,非常實(shí)用,需要的朋友可以參考下2014-10-10
jQuery動(dòng)態(tài)添加可拖動(dòng)元素完整實(shí)例(附demo源碼下載)
這篇文章主要介紹了jQuery動(dòng)態(tài)添加可拖動(dòng)元素的方法,可實(shí)現(xiàn)簡單的點(diǎn)擊添加元素,并且添加的元素可進(jìn)行拖動(dòng)操作.涉及jQuery響應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁面元素的相關(guān)技巧,需要的朋友可以參考下2016-06-06
jQuery用unbind方法去掉hover事件及其他方法介紹
jquery怎么去掉hover以為直接unbind(hover)就可以搞定,結(jié)果很失敗,接下來介紹下取消hover事件的多種方法,感興趣的你可以參考下哈2013-03-03
jquery的ajax如何使用ajaxSetup做全局請(qǐng)求攔截
在Web開發(fā)中,Ajax是一種常用的前后端數(shù)據(jù)交互技術(shù),由于業(yè)務(wù)需求的復(fù)雜性和安全性的考慮,我們可能需要對(duì)Ajax請(qǐng)求進(jìn)行全局?jǐn)r截和處理,以便統(tǒng)一處理一些共性問題,如權(quán)限驗(yàn)證、錯(cuò)誤處理等,本項(xiàng)目方案將介紹如何使用jQuery的Ajax實(shí)現(xiàn)全局請(qǐng)求攔截2023-11-11
jquery實(shí)現(xiàn)的橫向二級(jí)導(dǎo)航效果代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)的橫向二級(jí)導(dǎo)航效果代碼,可實(shí)現(xiàn)鼠標(biāo)滑過導(dǎo)航出現(xiàn)下拉菜單切換的效果,非常簡潔自然,涉及jquery鼠標(biāo)hover事件及頁面元素樣式的動(dòng)態(tài)改變技巧,需要的朋友可以參考下2015-08-08
jQuery截取指定長度字符串的實(shí)現(xiàn)原理及代碼
截取指定長度字符串操作在新聞列表這種類型的操作中大量應(yīng)用,下面有個(gè)示例,大家可以參考下2014-07-07

