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"; Do you like fruit best? <br /><br /> <label><input name= "Fruit" type= " Radio " value=" " /> Apple </label> <label><input name=" Fruit " type= "Radio" value= "" /> peach </label> <label><input Name= "Fruit" type= "Radio" value= "" /> banana </label> <label>< Input name= "Fruit" type= "Radio" value= "" /> pear </label> <label ><input name= "Fruit" type= "Radio" value= "" /> other </label> |
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= "Administrator"/> Administrator |
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 21st 22 23 24 25 26 27 28 29 30 |
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "> <script> <!-- Check 2 returned is also 1, find the first ID for that value of the DOM, popup 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> <body> <input type= "Radio" id= "test11" name= "test11" value= "1"/> Test 1 <input type= "Radio" id= "test11" name= "test11" value= "2"/> Test 2 <input type= "button" value= "Btn_byid" onclick= "Getvbyid ()"/> <input type= "button" value= "Btn_byname" onclick= "Getvbyname ()"/> </body> |
- Article Source:HTML <radio> radio button control label usage resolution and how to set the default check
HTML <radio> radio Button control label usage resolution and how to set default check