Home
Web Front-end
HTML Tutorial
Detailed explanation of examples of obtaining, assigning, and registering events for radio values in HTML_HTML/Xhtml_Web page production



Detailed explanation of examples of obtaining, assigning, and registering events for radio values in HTML_HTML/Xhtml_Web page production
May 16, 2016 pm 04:37 PM
html
1. Radio grouping
As long as the name is the same, it is a group, that is, only one can be selected in a group, as follows:
Copy code
The code is as follows:<span>group1:</span>
<input type="radio" id="radio1" checked= "checked" name="group1" />radio1
<input type="radio" id="radio2" name="group1" />radio2
<input type="radio" id= "radio3" name="group1" />radio3
<span>group2:</span>
<input type="radio" id="radio4" checked="checked" name="group2" />radio4
<input type="radio" id="radio5" name="group2" />radio5
<input type="radio" id="radio6" name="group2" />radio6
The effect is as follows:

2. Get the selected radio node
Using jquery can be very easy To make it easier, first select the group, and then filter out the checked ones, as follows:
Copy the code
The code is as follows :var group1 = $("[name='group1']").filter(":checked");
console.log(group1.attr("id")) ;
3, select a radio node
Use jquery to set the checked attribute:
Copy code
The code is as follows:$("#radio2").attr("checked", "checked");
4, go Select a radio node
to remove the checked attribute:
Copy the code
The code is as follows: $("#radio1").removeAttr("checked");
The result of this may be that none of the radios in the group is selected.
5. Register the select and deselect event
Or use jquery’s on function to register the change event, as follows:
Copy the code
The code is as follows:$("[name='group1']").on("change",
function (e) {
console.log($(e.target).val());
}
);
In this way, as long as any one in group1 is selected, it will trigger function.
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 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
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 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
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 do you parse and process HTML/XML in PHP?
