What does the HTML radio button check by default? Example of a radio button usage for the input tag

Source: Internet
Author: User
This article focuses on the use of radio buttons for HTML input tags, as well as the practice of radio default buttons for HTML input tags. Now let's take a look at this article.

First we introduce the practice of radio buttons in the HTML input tag:

<input> tags are used to collect user information. The input field has many forms, depending on the value of the type attribute. The input field can be a text field, a check box, a masked text control, a radio button, a button, and so on.

Words do not say much, on the code example:

<form action= "form_action.asp" method= "get" ><input type= "Radio" name= "Radio" value= "1" > Radio 1<input Type = "Radio" name= "Radio" value= "2" > Radio 2<input type= "Radio" name= "Radio" value= "3" > Radio 3<input type= "Radio" name = "Radio" value= "4" > Radio 4</form>

This effect is easy to see, let's look at the display in the browser first:

This effect can be seen at a glance, a very simple code

There is also a lot of sites are often seen, such as: Radio sex, this is basically used in this kind of box to make. The code is as follows:

The radio button in HTML implements male and female selection, does not allow both sexes to be able to choose, the implementation method: Write a Name property in the button's properties, and set the value of name to the same

<input id= "man" type= "Radio" checked= "Checked" name= "1"/> male <input id= "woman" type= "Radio"  name= "1"/> Female

This will not give a diagram, than the above that is simple, on the two radio box, we often encounter this.

Now let's say how the HTML Radio box button is selected by default:

First we take the first example and continue to say that we only need to add a property in it, as follows:

<form action= "form_action.asp" method= "get" ><input type= "Radio" name= "Radio" value= "1" > Radio 1<input Type = "Radio" name= "Radio" value= "2" checked> Radio 2<input type= "Radio" name= "Radio" value= "3" > Radio 3<input type= " Radio "Name=" Radio "value=" 4 "> Radio 4</form>

The effect is still obvious, see:

I do not have any click on the above, I appear on top of it, after the refresh can be seen on the Radio 2 above.

We can see, so that the radio box is selected by default, you can try it yourself, more knock code.

OK, the above is the article about the HTML input tag to do radio button, the problem can be asked below.

Related Article

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.