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

jQuery operation input type=radio implementation code_jquery

May 16, 2016 pm 05:52 PM
input Radio

<input type="radio"> is as follows:

Copy code The 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. 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".
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement laravel input hidden field How to implement laravel input hidden field Dec 12, 2022 am 10:07 AM

How to implement laravel input hidden field

How to encapsulate input components and unified form data in vue3 How to encapsulate input components and unified form data in vue3 May 12, 2023 pm 03:58 PM

How to encapsulate input components and unified form data in vue3

60 years in the making: NASA confirms hypothesis on Earth\'s global electric field 60 years in the making: NASA confirms hypothesis on Earth\'s global electric field Aug 31, 2024 pm 09:35 PM

60 years in the making: NASA confirms hypothesis on Earth\'s global electric field

Detailed explanation of input box binding events in Vue documents Detailed explanation of input box binding events in Vue documents Jun 21, 2023 am 08:12 AM

Detailed explanation of input box binding events in Vue documents

What to do if there is no cursor when clicking on the input box What to do if there is no cursor when clicking on the input box Nov 24, 2023 am 09:44 AM

What to do if there is no cursor when clicking on the input box

How to use the input box carriage return event and verification function in the Vue document How to use the input box carriage return event and verification function in the Vue document Jun 20, 2023 am 09:13 AM

How to use the input box carriage return event and verification function in the Vue document

What is the input element in jquery? What is the input element in jquery? Jun 06, 2023 pm 02:18 PM

What is the input element in jquery?

How to prohibit input in html5 input How to prohibit input in html5 input Feb 03, 2023 am 10:02 AM

How to prohibit input in html5 input

See all articles