<Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> javascript mouse Sliding Control </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 ); } // Automatically clear the table after the mouse leaves the table 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> |