Home>Article>Daily Programming> How to set check boxes, radio buttons and default options in HTML? (Pictures + Videos)
This article mainly introduceshow to set check boxes and radio buttonsin HTML.
In the process of website development, we sometimes need to implement functions similar to questionnaires. Since it is a questionnaire, single-select or multiple-select situations cannot be avoided. For novice friends, it may not be clear.
Below we will use a simple code example to introduce to youHow to set check boxes and radio buttonsin HTML.
HTML设置复选框、单选框
Access through the browser, the effect is as follows:
Here we directly refresh the browser, you can find that even if you do not select, single selection Boxes and checkboxes will have default options.
Detailed explanation of important tags and attributes:
##TagSpecifies the input field where the user can enter data.
According to different type attributes, input fields have various forms. Input fields can be text fields, checkboxes, password fields, radio buttons, buttons, etc. Here we use the "radio" attribute to set the radio button and "checkbox" to implement the check box and multi-select box.checked attributeSpecifies the input element that should be pre-selected when the page is loaded. Simply put, if we need to set the default option, just add the checked value to the specified input box. That's it.
Note:
When we add multiple checked values in the radio button box and want to set multiple default options, the last checked one will prevail. . As in the above code, we add two checked values to the radio buttonThe effect is as shown below: This article It is an introduction to the relevant knowledge about
HTML setting check boxandradio button. It is easy to understand. I hope it will be helpful to friends in need!
If you want to know more about front-end related knowledge, you can follow PHP Chinese websiteHTML video tutorial,CSS video tutorial,Bootstrap video tutorial, etc. Wait for relevant tutorials, welcome everyone to refer to and learn!
The above is the detailed content of How to set check boxes, radio buttons and default options in HTML? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!