Home  >  Article  >  Web Front-end  >  jQuery operation input type=radio implementation code

jQuery operation input type=radio implementation code

高洛峰
高洛峰Original
2017-02-11 17:11:071675browse

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=&#39;city&#39;]: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=&#39;city&#39;][value=&#39;YangZhou&#39;]").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":

$(&#39;input[name="city"]:checked&#39;).attr("checked",false);

4. Get the number of radios with name="city":

$("input[name=&#39;city&#39;]").length;

5. Get the radio with name="city" and the index is even:

$("input[name=&#39;city&#39;]:even");

The index starts from 0.

6. Get the radio with name="city" and the index is odd:

$("input[name=&#39;city&#39;]:odd");

The index starts from 0.

7. Iterate radio:

$("input[name=&#39;city&#39;]").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=&#39;city&#39;]").attr("disabled",true);

Disable the radio with name="city".

9. Enable radio:

$("input[name=&#39;city&#39;]").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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn