Settings of input radio

Source: Internet
Author: User

Settings of the radio type in the input control in html
Radio contains attributes such as id, name, value, and checked.
<Input type = "radio" id = "test" name = "test" checked = "checked">
If you create multiple radio instances and want multiple radio instances to belong to the same group (that is, the single-choice function), you need to set the name attribute of the value radio and the name has the same value, if this is not set, radio has the check function.
<Input type = "radio" id = "test" name = "test" value = "test 1">
<Input type = "radio" id = "test" name = "test" value = "test 2">
Below is a small example of radio:
<Script type = "text/javascript">
Function doclick (){
String id = document. getElementsByName ("test ");
For (var I = 0; I <id. length; I ++ ){
Var radio = id [I];
Alert (radio. value );
}
}
</Script>
 
<Body>
<Input type = "radio" id = "test" name = "test" value = "test 1"> test 1
<Input type = "radio" id = "test" name = "test" value = "test 2"> test 2
<Br>
<Input type = "button" id = "btn" value = "Select" onclick = "doclick ();">
 
</Body>

After clicking the button, the value of each radio value is output in sequence.

Set the radio checked attribute in jsp
<%
String test = "test 1 ";
%>
 
<Input type = "radio" id = "test" name = "test" value = "test 1"
<% = Test. equals ("test 1 ")? Checked: "" %> test 1
<Input type = "radio" id = "test" name = "test" value = "test 2"
<% = Test. equals ("test 2 ")? Checked: "" %> test 2
Checked is the abbreviation of checked = "checked. You can initialize the checked attribute.


This article is from the "TinyKing" blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.