萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> javascript鼠標滑動評分控件完整

javascript鼠標滑動評分控件完整

   本文實例講述了javascript鼠標滑動評分控件。分享給大家供大家參考。具體實現方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>javascript鼠標滑動控件</title> <script type="text/javascript"> function ArrayIndexof(arr, inElement) { for (var i = 0; i < arr.length; i++) { if (arr[i] == inElement) { return i; } } return -1; } function GetTDS() { var tbl = document.getElementById("tblMain"); var tds = tbl.getElementsByTagName("td"); return tds; } function iniEvent() { var tds = GetTDS(); for (var i = 0; i < tds.length; i++) { td = tds[i]; td.onmouseover = TdOnMouseOver; } var tbl = document.getElementById("tblMain"); tbl.onmouseout = TableMouseOut; } function SetRating(tdTmp) { var tds = GetTDS(); var index = ArrayIndexof(tds, tdTmp); for (var i = 0; i <= index; i++) { td = tds[i]; td.innerHTML = "★"; } for (var i = index + 1; i < tds.length; i++) { td = tds[i]; td.innerHTML = "☆"; } } function TdOnMouseOver() { SetRating(this); } //鼠標離開表格後自動清除 function TableMouseOut() { var tds = GetTDS(); for (var i = 0; i < tds.length; i++) { td = tds[i]; td.innerHTML = "☆"; } } </script> </head> <body onload="iniEvent()"> <table id="tblMain" border="1"> <tr> <td>☆</td> <td>☆</td> <td>☆</td> <td>☆</td> <td>☆</td> </tr> </table> </body> </html>

  希望本文所述對大家的javascript程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved