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
- $ (function () {
- $ ('. btn '). On (' click ', function () {
- Alert (' button is clicked ');
- });
- $ (' body '). Append ('<button class= "BTN" > Dynamically added Buttons </button> ');
- });
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
- <input type="checkbox" id="SelectAll" /> Select all
- <input type="checkbox" class="SelectRow" /> First row
- <input type="checkbox" class="SelectRow" /> second row
[JavaScript]View PlainCopy
- $ ( ' #selectAll '). On (function () {
- if ($ (this). Prop ( ' checked ')) {
- $ ( ' checked ', true);
- } else {
- $ (false)
- }
-
jQuery1.9 to dynamically add element binding events and to get and manipulate the select properties of a checkbox