jQuery1.9 to dynamically add element binding events and get and manipulate the checkbox's selection Properties 11

Source: Internet
Author: User

1.jQuery is a dynamically added element binding event: After 1.7, the live () method is added, 1.9 is removed, and 1.9 is available in the On () method:

[JavaScript]View PlainCopy 
    1. $ (function () {
    2. $ ('. btn '). On (' click ', function () {
    3. Alert (' button is clicked ');
    4. });
    5. $ (' body '). Append ('<button class= "BTN" > Dynamically added Buttons </button> ');
    6. });


2. Gets whether the checkbox is selected, and the action is selected:

A. Get the checked property by using the Prop method, get the checked return value of Boolean, check True, otherwise flase.

B. If the attr method is used to obtain, if the initialization of the current input does not have the checked attribute defined, the $ ("#selectAll") will be returned regardless of whether it is currently selected. attr ("checked") returns undefined;
If the checked attribute is already defined in the current input, the $ ("#selectAll") is returned regardless of whether it is selected or not. attr ("checked") will return checked

How to use:

[HTML]View PlainCopy 
    1. <input type="checkbox" id="SelectAll" /> Select all
    2. <input type="checkbox" class="SelectRow" /> First row
    3. <input type="checkbox" class="SelectRow" /> second row

[JavaScript]View PlainCopy 
      1. $ ( ' #selectAll '). On (function ()  {  
      2.      if  ($ (this). Prop ( ' checked '))   {  
      3.         $ ( ' checked ',  true);   
      4.     } else {  
      5.          $ (false)    
      6.      }  

jQuery1.9 to dynamically add element binding events and to get and manipulate the select properties of a checkbox

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.