jquery checkbox check box multiple clicks to determine the selected state, as well as the Select all/Cancel code example

Source: Internet
Author: User

December 21, 2015 10:52:51 Monday

Target, click on the current Checbox to determine whether the current checkbox is selected after the click.

Html:

<input type= "checkbox" onclick= "Contracts_checkall ()" id= "Contracts_checkall" > select All

Js:

1         var checkall = $ ("#contracts_checkall"). attr (' checked '); 2         var checkall_value1 = $ ("#contracts_checkall"). Val (); 3         var checkall_value2 = $ (' #contracts_checkall '). Is (': Checked '); 4         Console.log (checkall); 5         Console.log (checkall_value1); 6         Console.log (checkall_value2);

First time click:

1 undefined 2 undefined 3  on 4  true

Second click:

1 undefined 2 undefined 3  on 4  false

In summary, the IS () method can be used to determine the status of the current check box, even if there are no related properties

Select All/Deselect All

1 functionContracts_checkall ()2 {3     varCheckall = $ (' #contracts_checkall '). Is (': Checked '));6$ ("Input[name= ' contract[]" "). each (7         function () {8              This. checked=Checkall;9             //$ (this). attr (' checked ', checkall);//The first check and cancel are successful, and the selection will not work.Ten         } One     ); A}

jquery checkbox check box multiple clicks to determine the selected state, as well as the Select all/Cancel code example

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.