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