javascript鼠标滑动评分控件完整实例
本文实例讲述了javascript鼠标滑动评分控件。分享给大家供大家参考。具体实现方法如下:
<htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/> <title>javascript鼠标滑动控件</title> <scripttype="text/javascript"> functionArrayIndexof(arr,inElement){ for(vari=0;i<arr.length;i++){ if(arr[i]==inElement){ returni; } } return-1; } functionGetTDS(){ vartbl=document.getElementById("tblMain"); vartds=tbl.getElementsByTagName("td"); returntds; } functioniniEvent(){ vartds=GetTDS(); for(vari=0;i<tds.length;i++){ td=tds[i]; td.onmouseover=TdOnMouseOver; } vartbl=document.getElementById("tblMain"); tbl.onmouseout=TableMouseOut; } functionSetRating(tdTmp){ vartds=GetTDS(); varindex=ArrayIndexof(tds,tdTmp); for(vari=0;i<=index;i++){ td=tds[i]; td.innerHTML="★"; } for(vari=index+1;i<tds.length;i++){ td=tds[i]; td.innerHTML="☆"; } } functionTdOnMouseOver(){ SetRating(this); } //鼠标离开表格后自动清除 functionTableMouseOut(){ vartds=GetTDS(); for(vari=0;i<tds.length;i++){ td=tds[i]; td.innerHTML="☆"; } } </script> </head> <bodyonload="iniEvent()"> <tableid="tblMain"border="1"> <tr> <td>☆</td> <td>☆</td> <td>☆</td> <td>☆</td> <td>☆</td> </tr> </table> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。