jquery Dynamic Add Delete row of data sample

Source: Internet
Author: User

This article mainly introduces how jquery dynamically adds a delete row of data, the need for friends can refer to the following

<title> Add, delete one line </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script type= "Text/javascript" src= ". /js/jquery-1.9.1.js "></script>
<script type= "Text/javascript" >
$ (function () {
$ ("#addOneRow"). Click (function () {
var temptr = $ ("Tr:first"). Clone (True);
$ ("Tr:last"). After (TEMPTR);
$ ("Tr:last > td > #name"). Val ("");//new add row name is empty
$ ("Tr:last > td > #address"). Val ("");//new Add row address is empty
});
$ (". Delonerow"). Click (function () {
if ($ ("tr"). Length < 2) {
Alert ("Keep at least one row!");
} else {
if (Confirm ("Confirm deletion?") {
$ (this). Parent (). Parent (). remove ();
}
}
});
});
</script>

<body>
<table border= "1" >
<tr>
<td> name:</td>
<td><input type= "text" id= "name" name= "name"/>
</td>
<td> Address:</td>
<td><input type= "text" id= "Address" name= "Address"/></td>
<td><input type= "button" class= "Delonerow" value= "Delete"/></td>
</tr>
</table>
<input type= "button" id= "Addonerow" value= "Add Row"/>
</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.