Jquery學習筆記(2)--五角星評分

來源:互聯網
上載者:User

標籤:span   ext   body   this   script   tar   jquer   var   nbsp   

網購五星評分類比:

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Document</title> 6     <script type="text/javascript" src="jquery.js"></script> 7 </head> 8 <body> 9     <div>10         <span class="star">☆</span>11         <span class="star">☆</span>12         <span class="star">☆</span>13         <span class="star">☆</span>14         <span class="star">☆</span>15     </div>16 </body>17     <script type="text/javascript">18         var isclick = 0;19         var clicknum = 0;20         //滑鼠滑過,編程黑五角星21         $(‘span‘).mouseover(function(){22             // if (isclick==0) {23                 var num = $(this).index();24                 // alert(num);25                 $(‘span‘).each(function(){26                     if ($(this).index()<=num) {27                         $(this).html(‘★‘);28                     }else{29                         if ($(this).index()>clicknum) {30                             $(this).html(‘☆‘);31                         }32                     }33                 });34             // }35         });36         //滑鼠離開div,變回空心五角星37         $(‘div‘).mouseleave(function(){38             if (isclick==0) {39                 $(‘span‘).each(function(){40                     if ($(this).index()>clicknum) {}41                     $(this).html(‘☆‘);42                 });43             }else{44                 $(‘span‘).each(function(){45                     if ($(this).index()>clicknum) {46                         $(this).html(‘☆‘);47                     }48                 });49             }50         });51         //滑鼠點擊,固定黑五角星,並且重新點擊後重新固定,離開後不變52         $(‘span‘).click(function(){53             isclick = 1;54             clicknum = $(this).index();55             $(‘span‘).each(function(){56                 if ($(this).index()<=clicknum) {57                     $(this).html(‘★‘);58                 }else{59                     $(this).html(‘☆‘);60                 }61             });62         });63     </script>64 </html>

 

Jquery學習筆記(2)--五角星評分

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.