Select Delete is often used in the background management, its own JS level is weak, so write down, easy to use later.
HTML code:
<Table> <thead> <TR> <TD><inputclass= "SelectAll"type= "checkbox"></TD> <TD>Id</TD> <TD>Name</TD> <TD>Age</TD> <TD>Gender</TD> </TR> </thead> <tbodyID= "Content"> <TR> <TD><inputname= "Check"type= "checkbox"></TD> <TD>123</TD> <TD>Zhangsan</TD> <TD>24</TD> <TD>Do?</TD> </TR>" "</tbody></Table> <Buttonclass= "DeleteAll">Delete all</Button>
JS Code:
$ ('. SelectAll '). On (' click ',function () { if( This. Checked) { $(' Table input[name= ' check ']. Prop (' checked '),true). Val (' 1 '); } Else { $(' Table input[name= ' check ']. Prop (' checked '),false). Val (' 0 '); } }); $('. DeleteAll '). On (' click ',function () { if(Confirm (' OK to delete this data? ‘)){ varChecks = $ (' Table input[name= ' check ']:checked '); if(Checks.length = = 0) {alert (' No data is selected! ‘); return false; } $(' Table Tbody '). Find (': checkbox[value=1] '). Parents (' tr ')). Remove (); $ ('.SelectAll'). Prop (' Checked ',false); }})//Reset all marquee to an unchecked state
This is done by adding value to the selected checkbox, and then deleting the element with that value. Of course, you can add other properties, such as data-* or something.
JQuery Select all Delete