Jqurey Select All and select All

Source: Internet
Author: User

<Scriptsrc= "Http://code.jquery.com/jquery-1.4.4.min.js"type= "Text/javascript"></Script>    <Scripttype= "Text/javascript">        $(function() {           $("#checkAll"). Click (function() {                $('input[name= "Subbox"]'). attr ("checked", This. Checked);            }); var$subBox= $("input[name= ' Subbox ']"); $subBox. Click (function(){                $("#checkAll"). attr ("checked", $subBox. Length== $("input[name= ' Subbox ']:checked"). Length? true : false);        });    }); </Script> </Head><Body>    <Div>        <inputID= "Checkall"type= "checkbox" />Select All<inputname= "Subbox"type= "checkbox" />Item 1<inputname= "Subbox"type= "checkbox" />Item 2<inputname= "Subbox"type= "checkbox" />Item 3<inputname= "Subbox"type= "checkbox" />Item 4</Div></Body>

There's a problem with attr. Select all only use the first run once, click on the checkbox for all, you can select all, click once, or cancel all. However, after all, no matter what the click, it is useless ...

Baidu a bit with prop replace use attr can le

Difference http://www.cnblogs.com/zhwl/p/3520162.html

<Scriptsrc= "Http://code.jquery.com/jquery-1.4.4.min.js"type= "Text/javascript"></Script>    <Scripttype= "Text/javascript">        $(function() {           $("#checkAll"). Click (function() {                $('input[name= "Subbox"]'). Prop ("checked", This. Checked);            }); var$subBox= $("input[name= ' Subbox ']"); $subBox. Click (function(){                $("#checkAll"). Prop ("checked", $subBox. Length== $("input[name= ' Subbox ']:checked"). Length? true : false);        });    }); </Script> </Head><Body>    <Div>        <inputID= "Checkall"type= "checkbox" />Select All<inputname= "Subbox"type= "checkbox" />Item 1<inputname= "Subbox"type= "checkbox" />Item 2<inputname= "Subbox"type= "checkbox" />Item 3<inputname= "Subbox"type= "checkbox" />Item 4</Div></Body>

Jqurey Select All and select All

Related Article

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.