jquery Select All Delete

Source: Internet
Author: User

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

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.