<Input type = "radio"> as follows:
Copy codeThe Code is as follows:
<Input type = "radio" name = "city" value = "BeiJing"> BeiJing
<Input type = "radio" name = "city" value = "TianJin"> TianJin
<Input type = "radio" name = "city" value = "NanJing"> NanJing
<Input type = "radio" name = "city" value = "YangZhou"> YangZhou
<Input type = "radio" name = "city" value = "SuZhou"> SuZhou
1. Obtain the value of the selected radio:
Copy codeThe Code is as follows: $ ("input [name = 'city']: checked"). val ();
Use the element selector, use the attribute Filter name = 'city', and use: checked to select the selected element.
2. Set the selected status for the specified radio value:
Copy codeThe Code is as follows: $ ("input [name = 'city'] [value = 'yangzhou ']"). attr ("checked", true );
Set the radio status for name = "city" and value = "YangZhou.
3. deselect the radio status of name = "city:
Copy codeThe Code is as follows: $ ('input [name = "city"]: checked'). attr ("checked", false );
4. Obtain the number of radio for name = "city:
Copy codeThe Code is as follows: $ ("input [name = 'city']"). length;
5. obtain radio with name = "city" and an even number of indexes:
Copy codeThe Code is as follows: $ ("input [name = 'city']: even ");
The index starts from 0.
6. Obtain the radio with name = "city" and an odd index:
Copy codeThe Code is as follows: $ ("input [name = 'city']: odd ");
The index starts from 0.
7. Iterative radio:
Copy codeThe Code is as follows: $ ("input [name = 'city']"). each (function (I, obj ){
// I, subscript of iteration, starting from 0
// Obj, the current object (HTMLInputElement). You can use the obj. value format to obtain the attribute value.
// $ (This); the current jQuery object. You can use $ (this). val () to obtain the attribute value.
});
Iteration name = "city" radio.
8. Disable radio:
Copy codeThe Code is as follows: $ ("input [name = 'city']"). attr ("disabled", true );
Disable radio for name = "city.
9. enable radio:
Copy codeThe Code is as follows: $ ("input [name = 'city']"). attr ("disabled", false );
Enable radio for name = "city.