Home > Article > Web Front-end > jQuery operation input type=radio implementation code
d11dad02a1f3abd212da65221b2dc681 as follows:
<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:
$("input[name='city']:checked").val();
Use the element selector and then use the attribute filter name= 'city', and finally use:checked to select the selected elements.
2. Set the selected state for the radio with the specified value:
$("input[name='city'][value='YangZhou']").attr("checked",true);
Set the selected state for the radio with name="city" and value="YangZhou".
3. Cancel the selection status of the radio with name="city":
$('input[name="city"]:checked').attr("checked",false);
4. Get the number of radios with name="city":
$("input[name='city']").length;
5. Get the radio with name="city" and the index is even:
$("input[name='city']:even");
The index starts from 0.
6. Get the radio with name="city" and the index is odd:
$("input[name='city']:odd");
The index starts from 0.
7. Iterate radio:
$("input[name='city']").each(function(i,obj){ //i,迭代的下标,从0开始 //obj,当前的对象(HTMLInputElement),可以使用obj.value格式获取属性值 //$(this);当前jQuery对象,可以使用$(this).val()获取属性值 });
Iterate the radio with name="city".
8. Disable radio:
$("input[name='city']").attr("disabled",true);
Disable the radio with name="city".
9. Enable radio:
$("input[name='city']").attr("disabled",false);
Enable the radio with name="city".
For more jQuery operation input type=radio implementation code related articles, please pay attention to the PHP Chinese website!