基于jQuery實現(xiàn)的美觀星級評論打分組件代碼
本文實例講述了基于jQuery實現(xiàn)的美觀星級評論打分組件代碼。分享給大家供大家參考,具體如下:
這款jquery星級評論打分組件,是通用打分組件,callBack打分后執(zhí)行的回調(diào),this.Index:獲取當(dāng)前選中值。
運行效果截圖如下:
在線演示地址如下:
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è)計有所幫助。
相關(guān)文章
jQuery基于ajax()使用serialize()提交form數(shù)據(jù)的方法
這篇文章主要介紹了jQuery基于ajax()使用serialize()提交form數(shù)據(jù)的方法,結(jié)合實例形式較為詳細(xì)的分析了jQuery使用ajax提交serialize序列化后的表單數(shù)據(jù)的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12基于jQuery的$.getScript方法去加載javaScript文檔解析
下面小編就為大家?guī)硪黄趈Query的$.getScript方法去加載javaScript文檔解析。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11jQuery中clone()函數(shù)實現(xiàn)表單中增加和減少輸入項
這篇文章給大家介紹了jQuery中clone()函數(shù)實現(xiàn)表單中增加和減少輸入項的實例代碼,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2017-05-05