Home > Web Front-end > JS Tutorial > jQuery operation input type=radio implementation code_jquery

jQuery operation input type=radio implementation code_jquery

WBOY
Release: 2016-05-16 17:52:54
Original
1184 people have browsed it

is as follows:

Copy code The code is as follows:

Beijing
Tianjin
< input type="radio" name="city" value="NanJing">Nanjing
Yangzhou
Suzhou

1. Get the value of the selected radio:

Copy code The code is as follows:
$("input[name='city']:checked").val();


Use the element selector, then use the attribute filter name='city', and finally use: checked to select the selected element.

2. Set the selected state for the radio with the specified value:

Copy the code The code is as follows:
$("input[name='city'][value='YangZhou']").attr("checked",true);


Give name="city" And the radio setting with value="YangZhou" is selected.

3. Uncheck the radio with name="city":

Copy code Code As follows:
$('input[name="city"]:checked').attr("checked",false);


4. Get name="city" The number of radios:

Copy code The code is as follows:
$("input[name ='city']").length;


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

Copy code The code is as follows:
$("input[name='city']:even");


Index is from Starting from 0.

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

Copy code The code is as follows:
$("input[name='city']:odd");


Index starts from 0.

7. Iterate radio:

Copy code The code is as follows:
$ ("input[name='city']").each(function(i,obj){
//i, the subscript of the iteration, starting from 0
//obj, the current object (HTMLInputElement) , you can use the obj.value format to get the attribute value
//$(this); for the current jQuery object, you can use $(this).val() to get the attribute value
});

Iterate over the radio with name="city".

8. Disable radio:

Copy code The code is as follows:
$ ("input[name='city']").attr("disabled",true);


Disable the radio with name="city".

9. Enable radio:

Copy code The code is as follows:
$ ("input[name='city']").attr("disabled",false);


Enable the radio with name="city".
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template