Ranking exercise: add data to a table. When the number is repeated, you are prompted that the data cannot be added, and you can add data in the ranking order.
ReferenceCode:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <HTML> Function Test (){ // Obtain table objects VaR Mytable = Document. getelementbyid ("Table1" ); // Determine whether to insert a duplicate ranking // Traversal // Define the position of the variable to be inserted VaR Insertw = Mytable. Rows. length; For ( VaR I = 1; I <mytable. Rows. length; I ++ ){ // Retrieve each row VaR Erows = Mytable. Rows [I]; // Judge whether the input ranking is repeated If (Erows. cells [0]. innertext = No. Value) {window. Alert ( "Same as ranking" + erows. cells [0]. innertext +" ); Return ; // Block Code Execution below } // Sort To find the location to insert If (Parseint (No. Value)> parseint (erows. cells [0 ]. Innertext) {insertw =I; // Window. Alert (insertw ); } // Window. Alert ("OK "); } // Insert after sorting VaR Eachrow = mytable. insertrow (insertw + 1 ); // Add data to each row Eachrow. insertcell (0). innertext = Document. getelementbyid ("no"). Value; eachrow. insertcell ( 1). innertext = Username. value; eachrow. insertcell ( 2). innertext = Nickname. value ;} </SCRIPT> Ranking: <Input id = "no" type = "text" name = "no"> <br/> Name: <input id = "username" type = "text" name = "username"> <br/> nickname: <input id = "nickname" type = "text" name = "nickname"> <br/> <input type = "button" value = "add" onclick = "test () "> <br/> </body>