Bulk Delete-check box

Source: Internet
Author: User

In the project to be used in the bulk delete, delete the need to check box, now posted code for later use.

The HTML code is as follows

<Buttonclass= "btn btn-xs btn-danger"onclick= "Delbatchinfo (' Patroltask ')"><Iclass= "Ace-icon fa fa-trash-o bigger-120"></I>Delete check box</Button><TableID= "DataTable"class= "Table table-striped table-bordered table-hover">    <thead><TR><thclass= "Center"><label><inputtype= "checkbox"class= "Ace"name= "Delbatch"/><spanclass= "LBL"></span></label></th><thclass= "Center">Number</th></TR> </thead>    <tbody><TR><thclass= "Center"><label><inputtype= "checkbox"class= "Ace"name= "Delbatch" name= "Delbatch" value= "' +data.data[item].id+ '"/><spanclass= "LBL"></span></label></th><TDclass= "Center"></TD></TR></tbody></Table>

Js

function () {    varthis;    $ (this). Closest (' table '). "Find (' tr > Td:first-child input:checkbox ')    . each (  function() {        this. Checked= that.checked;        $ (this). Closest (' tr '). Toggleclass (' selected ');});
Delbatchinfo method
/********************************************** function Name: delbatchinfo function: Delete records in bulk milan******************************** ****************/functionDelbatchinfo (type) {varDelmesshtml= ""; varcheckednum=$ ("Input[name= ' Delbatch ']:checked"). length; if(Checkednum = = 0) {alert ("Please select Delete Object!" "); return; }             if(Confirm ("Warning: Do you want to completely delete records?") ")){varcheckedlist=NewArray (); $("#datatable"). Find (' tr > Td:first-child input:checkbox '). each (function() {Checkedlist.push ($ ( This). Val ());        }); }        ...            }

When I pass a value in the delete prompt, the deletion error, the error code is as follows:

if (Confirm ("Warning: Do you want to completely delete records?") ")) {    var checkedlist=New  Array ();    $ ("input[name= ' Delbatch ']:checked"). each (function() {        Checkedlist.push ($ (  ). Val ());    });

Reason is

$ ("Input[name= ' Delbatch ']:checked"). each (function() {
This code iterates through all the checkboxes, including the check boxes that are always checked. The total check box does not have an ID value.
The correct code should:
$ ("#datatable"). Find (' tr > Td:first-child input:checkbox ')

This is the only option to select the TD check box in TR


After each deletion, after the setlisttable (nowpage) Refresh page, the total check box still handles the tick state,


Only the contents of Table>thead can be put into the Setlisttable method to solve
var tablehmtl= '<thead><TR><thclass= "Center"><label><inputtype= "checkbox"class= "Ace"name= "Delbatch"ID= "Checkall"/><spanclass= "LBL"></span></label></th><thclass= "Center">Number</th></TR> </thead> <tbody>'; tablehmtl+= '<TR><TDclass= "Center"><label><inputtype= "checkbox"class= "Ace"name= "Delbatch"value= "' +data.data[item].id+ '"/><spanclass= "LBL"></span></label></TD><TDclass= "Center">' +data.data[item].id+ '</TD><TR>'; tablehmtl+= '</tbody>';                                     $ ("#datatable"). HTML (TABLEHMTL); 




Bulk Delete-check box

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.