jquery operation <input type= "Radio" >
<input type= "Radio" > as follows:
12345 |
< input type="radio" name="city" value="BeiJing">北京 < input type="radio" name="city" value="TianJin">天津 < input type="radio" name="city" value="NanJing">南京 < input type="radio" name="city" value="YangZhou">扬州 < input type="radio" name="city" value="SuZhou">苏州 |
1. Get the value of the selected radio:
1 |
$("input[name=‘city‘]:checked").val(); |
Use the element selector, then use the attribute filter name= ' city ', and finally use: checked select the selected element.
2. Set the selected state to the radio of the specified value:
1 |
$("input[name=‘city‘][value=‘YangZhou‘]").attr("checked",true); |
Give Name= "City" and Value= "Yangzhou" Radio set the selected state.
3. Cancel the selected state of the Name= "City" Radio:
1 |
$(‘input[name="city"]:checked‘).attr("checked",false); |
4. Get the number of radio of Name= "City":
1 |
$("input[name=‘city‘]").length; |
5. Get Name= "City" and the index is even radio:
1 |
$("input[name=‘city‘]:even"); |
The index is starting from 0.
6. Get Name= "City" and the index is odd radio:
1 |
$("input[name=‘city‘]:odd"); |
The index is starting from 0.
7. Iterative Radio:
12345 |
$("input[name=‘city‘]").each(function(i,obj){ //i,迭代的下标,从0开始 //obj,当前的对象(HTMLInputElement),可以使用obj.value格式获取属性值 //$(this);当前jQuery对象,可以使用$(this).val()获取属性值 }); |
Iterate name= the radio of "City".
8. Disable Radio:
1 |
$("input[name=‘city‘]").attr("disabled",true); |
Disables the radio of Name= "City".
9. Enable Radio:
1 |
$("input[name=‘city‘]").attr("disabled",false); |
Enable the radio of Name= "City".
jquery operation <input type= "Radio" >