HTML <radio> radio Button control label usage resolution and how to set default check

Source: Internet
Author: User
Tags control label

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 < formaction = ""method = "get" > 您最喜欢水果?< br/>< br/> < label >< inputname = "Fruit"type = "radio"value = ""/>苹果 </ label > < label >< inputname = "Fruit"type = "radio"value = ""/>桃子 </ label > < label >< inputname = "Fruit"type = "radio"value = ""/>香蕉 </ label > < label >< inputname = "Fruit"type = "radio"value = ""/>梨 </ label > < label >< inputname = "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 > < metahttp-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 >      < inputtype = "radio"id = "test11"name = "test11"value = "1"/>测试1      < inputtype = "radio"id = "test11"name = "test11"value = "2" />测试2      < inputtype = "button"value = "BTN_ByID"onclick = "getVById()"/>      < inputtype = "button"value = "BTN_ByName"onclick = "getVByName()"/> </ body > < html >
    • Article Source: HTML <radio> radio button control label usage resolution and how to set default check


HTML <radio> radio Button control label usage resolution and how to set default check

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.