Jquery dynamically adds table tr, deletes tr, selects all checkbox, and obtains data after TR is added and deleted. jquerycheckbox

Source: Internet
Author: User

Jquery dynamically adds table tr, deletes tr, selects all checkbox, and obtains data after TR is added and deleted. jquerycheckbox

I have not mentioned the question about how to add table tr dynamically in jquery. The above code is annotated in many places.

For the edited table data returned, I want to say that I directly save it as a connected string in the format of str = XXX | XXX, XXX | XXX, XXX | XXX

You can also save it as an object type to facilitate background operations.

Let's talk about the direct code:

<Html> 

Note that jquery js should be referenced. The jquer JS here is in the same directory as the webpage.


How does js dynamically add tr and delete the row selected by the checkbox?

Function del (){
Var tab = document. getElementById ('hrstables ');
For (var I = tab. rows. length-1; I> 0; I --){
If (tab. rows [I]. cells [0]. getElementsByTagName ('input') [0]. checked ){
Tab. deleteRow (I );
}
}
}

How does Jquery Delete multiple rows selected by the checkbox in a table?

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "www.w3.org/TR/html4/loose.dtd">

<Html>
<Head>
<Title> </title>
<Script src = "jquery-1.6.4.min.js"> </script>
<Script>
$ (Function (){
$ (': Checkbox [name = all]'). click (function (){
If (this. checked ){
$ (': Checkbox'). attr ('checked', 'checked ');
} Else {
$ (': Checkbox'). removeAttr ('checked ');
}
})
$ ('Button '). click (function (){
Var num = 0;
$ (': Checkbox [name = child]'). each (function (){
If ($ (this). attr ('checked ')){
$ (This). closest ('tr'). remove ();
Num ++;
}
})
Alert ('total deleted ['+ num +'] row ');
})
})
</Script>
</Head>

<Body>

<Table id = "tab">
<Tr>
<Td> <input type = "checkbox" name = "all"/> </td>
<Td> id </td>
<Td> value </td>
</Tr>
<Tr>
<Td> <input type = "checkbox" name = "child"/> </td>
<Td> 111 </td>
<Td> 222 </td>
</Tr>
<Tr>
<Td> <input type = "check ...... remaining full text>

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.