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
});
//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
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement laravel input hidden field

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

Detailed explanation of input box binding events in Vue documents

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
