Work case 1 everything is caused by check, case check
In HTML, the input tag has two types: radio and checkbox. One single choice button and one check button. Jquery can select them through $ (": radio") and $ (": checkbox"). If you want to select the selected button, jquery can use $ (: checked).
Jquery judges three methods of checked (reposted content ):
. Attr ('checked'): // check version 1.6 + and return: "checked" or "undefined". 1.5-return: true or false
. Prop ('checked'): // 16 +: true/false
. Is (': checked'): // All Versions: true/false // do not forget the colon.
Several methods of jquery value assignment checked:
All jquery versions can be assigned the following values:
// $ ("# Cb1"). attr ("checked", "checked ");
// $ ("# Cb1"). attr ("checked", true );
Four values of jquery1.6 +: prop:
// $ ("# Cb1"). prop ("checked", true); // you can leave it simple.
// $ ("# Cb1"). prop ({checked: true}); // map key-Value Pair
// $ ("# Cb1"). prop ("checked", function (){
Return true; // The function returns true or false.
});
// Remember this: $ ("# cb1"). prop ("checked", "checked ");
Problem: multiple choice invert Selection
How to Use the selector mentioned above to complete the multiple-choice and inverse-selection functions. The single-choice and check buttons can be triggered by the click () event or the change () event.
There are several methods to change the selected or selected status:
Jquer Method
Attr () method and prop () method (reproduced)
When selecting all the check boxes, a problem occurs. Use the statement $. attr ('checked', true): Change the attribute of the check box to be selected. The first time you click "valid" in chrome, it will not work. IE8 is correct.
Baidu has been searching for a long time because HTML attributes are divided into attribute and property. The latter is called a feature for the moment.
The checked attribute is divided into attribute-> checked, and property-> true, false.
For a checkbox, if checked = "checked" is not defined, the result of alert ($. attr ("checked") is undefined. If defined, the result is checked. Attribute does not change with the status of the checkbox.
If prop ($. attr ("checked") is used, the output values are false and true, respectively. Property changes as it changes.
Therefore, you must use prop () to modify the checked attribute (). Prop () is added after jQuery1.6.
The following table is recommended for modifying attributes.
Javascript Method
CheckboxObject. checked = true | false
The following is a simple code for implementing the Single-choice and inverse-selection functions.
1