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>