Javascipt-dom programming table object exercises

Source: Internet
Author: User

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> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.