基於jQuery實現的美觀星級評論打分組件代碼,jquery打分

來源:互聯網
上載者:User

基於jQuery實現的美觀星級評論打分組件代碼,jquery打分

本文執行個體講述了基於jQuery實現的美觀星級評論打分組件代碼。分享給大家供大家參考,具體如下:

這款jquery星級評論打分組件,是通用打分組件,callBack打分後執行的回調,this.Index:擷取當前選中值。

運行效果如下:

線上示範地址如下:

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程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.