Jquery dynamic cyclic output table specific method _jquery

Source: Internet
Author: User
Implementation features:
1, a classmate asked me to implement a function like PHP, enter a number in the form, and then the page will appear the corresponding number; if it is PHP is much simpler, jquery implementation is the first, the beginning of the mad experiment, and finally realized (Knowledge point: jquery Create nodes, Gets the value of the form, the Loop statement)
jquery Code:
Copy Code code as follows:

<script type= "Text/javascript" language= "JavaScript" >
$ (function () {
$ ("#btn"). Click (function () {//SELECT element with ID btn, add click event
var result = $ ("input[name= ' text ']"). Val (); Gets the value of the text box with the name ' text ' and defines it as a variable result
$ ("div"). Remove (". abc"); The function is to delete the div containing the. ABC class every time it is executed;

for (i=1;i<=result;i++) {//for loop, set I=1, add 1 to each loop, and stop the loop when I's value from 1 loops to the value equal to result (that is, "the value of the text box's name= ')"
var createobj = $ ("<div class= ' abc ' > Nodes created </div>"); Define DIV as variable createobj
$ ("Body"). Append (Createobj); Append the createobj variable to the ' body ' in HTML
}

});
});
</script>

HTML code:

Copy Code code as follows:

<body>
<input type= "text" id= "text" name= "text"/>
<input type= "button" id= "btn" value= "OK"/>

</body>

CSS code:
Copy Code code as follows:

<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.