Jquery Dynamic Loop output table

Source: Internet
Author: User

Implementation Functions: 1. A student asked me to implement such a function, like PHP. Enter a number in the form and then the corresponding number appears on the webpage; if it is PHP, it will be much simpler. Jquery is still the first implementation, so we will start a crazy experiment and finally implement it (knowledge point: Jquery creates nodes, obtains form values, and loops) jquery code: <script type = "text/javascript" language = "javascript" >$ (function () {$ ("# btn "). click (function () {// select the element whose ID is btn and add the click Event var result = $ ("input [name = 'text']"). val (); // obtain the value of the text box whose name is 'text' and define it as the result $ ("div") variable "). remove (". abc "); // The role is to include each execution. delete the div of the abc class; for (I = 1; I <= result; I ++) {// for Loop, set I = 1, and Add 1 for each loop; when the I value is the same from 1 to the value equal to result (that is, "name = 'text' value of the text box ") stop the loop var createobj =$ ("<div class = 'abc'> created node </div> "); // define div as the variable createobj $ ("body "). append (createobj); // append the createobj variable to the 'body' in html}); </script> HTML code: <body> <input type = "text" id = "text" name = "text"/> <input type = "button" id = "btn" value = "OK "/> </body> CSS code: <style>. abc {height: 50px; width: 50px; margin: 20px; background: # ccc ;}</style>

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.