The Radio object represents a radio button in an HTML form. <input type= "Radio" in an HTML form > A Radio object is created every time it appears.
A radio button is one of a set of mutually exclusive option buttons. When a button is selected, the previously selected button becomes unchecked. When the radio button is selected or unchecked, the button triggers the onclick event handle. You can access the Radio object by traversing the elements[] array of the form, or by using document.getElementById (). collected and collated by Www.169it.com
One, radio button control syntax
1 |
< input name = "Fruit" type = "radio" value = "" /> |
Using the HTML input tag, name is a custom, type "Radio" form.
Second, radio radio button code example
1. HTML code snippet:
1 2 3 4 5 6 7 8 |
< form
action = ""
method = "get" > 您最喜欢水果?< br
/>< br
/> < label >< input
name = "Fruit"
type = "radio"
value = ""
/>苹果 </ label > < label >< input
name = "Fruit"
type = "radio"
value = ""
/>桃子 </ label > < label >< input
name = "Fruit"
type = "radio"
value = ""
/>香蕉 </ label > < label >< input
name = "Fruit"
type = "radio"
value = ""
/>梨 </ label > < label >< input
name = "Fruit"
type = "radio"
value = ""
/>其它 </ label > </ form > |
2. Example code fragment two (default Check setting example):
1 2 3 |
< input type = "Radio" name = "Identity" value = students checked = "Checked" /> students < input type = Radio name = "Identity" value = "Teacher" /> teacher < input type = Radio name = "Identity" value = "admin" /> Admin |
In the code example two, checked= "checked" means the default check setting.
3. code example three (JS Operation Radio):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < html > < head > < meta
http-equiv = "Content-Type"
content = "text/html; charset=gbk" > < script > <!-- //选中2返回的也是1,找到第一个ID为该值的DOM,弹出 1 function getVById(){alert(document.getElementById(‘test11‘).value);} function getVByName(){ var tt = document.getElementsByName(‘test11‘); for (var iIndex = 0; iIndex < tt.length ; iIndex++ ) { if(tt[iIndex].checked) { alert(tt[iIndex].value); break; } } }; --> </ script > < title >http://www.169it.com</ title > </ head > < body > < input
type = "radio"
id = "test11"
name = "test11"
value = "1"
/>测试1 < input
type = "radio"
id = "test11"
name = "test11"
value = "2" />测试2 < input
type = "button"
value = "BTN_ByID"
onclick = "getVById()"
/> < input
type = "button"
value = "BTN_ByName"
onclick = "getVByName()"
/> </ body > < html > |
HTML <radio> radio Button control label usage resolution and how to set default check