基于jQuery實(shí)現(xiàn)的美觀星級評論打分組件代碼
本文實(shí)例講述了基于jQuery實(shí)現(xiàn)的美觀星級評論打分組件代碼。分享給大家供大家參考,具體如下:
這款jquery星級評論打分組件,是通用打分組件,callBack打分后執(zhí)行的回調(diào),this.Index:獲取當(dāng)前選中值。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-rate-dfzj-codes/
具體代碼如下:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jquery星級評論打分組件</title>
<script src="jquery-1.6.2.min.js"></script>
<script>
var pRate = function(box,callBack){
this.Index = null;
var B = $("#"+box),
rate = B.children("i"),
w = rate.width(),
n = rate.length,
me = this;
for(var i=0;i<n;i++){
rate.eq(i).css({
'width':w*(i+1),
'z-index':n-i
});
}
rate.hover(function(){
var S = B.children("i.select");
$(this).addClass("hover").siblings().removeClass("hover");
if($(this).index()>S.index()){
S.addClass("hover");
}
},function(){
rate.removeClass("hover");
})
rate.click(function(){
rate.removeClass("select hover");
$(this).addClass("select");
me.Index = $(this).index() + 1;
if(callBack){callBack();}
})
}
</script>
<style type="text/css">
h1{font:26px/3 'microsoft yahei','simhei';color:#000;text-indent:2em;text-shadow:1px 1px 2px #ccc}
.p_rate{height:14px;position:relative;width:80px;overflow:hidden;display:inline-block;background:url(images/rate.png) repeat-x;margin:40px 100px}
.p_rate i{position:absolute;top:0;left:0;cursor:pointer;height:14px;width:16px;background:url(images/rate.png) repeat-x 0 -500px}
.p_rate .select{background-position:0 -32px}
.p_rate .hover{background-position:0 -16px}
</style>
</head>
<body>
<h1>jquery星級評論打分組件</h1>
<span class="p_rate" id="p_rate">
<i title="1分"></i>
<i title="2分"></i>
<i title="3分"></i>
<i title="4分"></i>
<i title="5分"></i>
</span>
<script>
var Rate = new pRate("p_rate",function(){
alert(Rate.Index+'分')
});
</script>
</body>
</html>
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- jquery 新浪網(wǎng)易的評論塊制作
- jquery實(shí)現(xiàn)仿新浪微博評論滾動效果
- 基于jquery實(shí)現(xiàn)ajax無刷新評論
- jQuery實(shí)現(xiàn)的簡單無刷新評論功能示例
- jQuery 實(shí)現(xiàn)評論等級好評差評特效
- JQuery實(shí)現(xiàn)動態(tài)添加刪除評論的方法
- PHP結(jié)合jQuery實(shí)現(xiàn)的評論頂、踩功能
- jQuery基于ajax實(shí)現(xiàn)星星評論代碼
- C#使用jQuery實(shí)現(xiàn)無刷新評論提交的方法
- jQuery實(shí)現(xiàn)簡單評論區(qū)
相關(guān)文章
jQuery操作復(fù)選框(CheckBox)的取值賦值實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery操作復(fù)選框(CheckBox)的取值賦值實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-01-01
淺析jQuery中調(diào)用ajax方法時在不同瀏覽器中遇到的問題
這篇文章主要介紹了jQuery中調(diào)用ajax方法時在不同瀏覽器中遇到的問題,因不同瀏覽器默認(rèn)設(shè)置的不同造成的問題2014-06-06
基于jquery的修改當(dāng)前TAB顯示標(biāo)題的代碼
在當(dāng)前tab選項(xiàng)卡中單擊鏈接后,新內(nèi)容在當(dāng)前選項(xiàng)卡中顯示,但標(biāo)題內(nèi)容還是上一頁標(biāo)題要改為新的標(biāo)題。2010-12-12
jQuery UI 實(shí)現(xiàn)email輸入提示實(shí)例
本文為大家介紹下使用jQuery UI 實(shí)現(xiàn)email輸入提示,具體思路如下,感興趣的朋友可以參考下2013-08-08
jQuery點(diǎn)擊tr實(shí)現(xiàn)checkbox選中的方法
jQuery點(diǎn)擊tr實(shí)現(xiàn)checkbox選中的方法,需要的朋友可以參考一下2013-03-03
jquery統(tǒng)計(jì)輸入文字的個數(shù)并對其進(jìn)行判斷
判斷輸入文字個數(shù)并提示還可以輸入多少個字,類似的功能使用jquery便可輕松實(shí)現(xiàn)2014-01-01
jQuery實(shí)現(xiàn)的隔行變色功能【案例】
這篇文章主要介紹了jQuery實(shí)現(xiàn)的隔行變色功能,結(jié)合具體實(shí)例形式分析了jQuery事件響應(yīng)、元素遍歷及屬性動態(tài)操作相關(guān)使用技巧,需要的朋友可以參考下2019-02-02

