单选按钮:一般用在 HTML 表单中。当您需要从网站访问者那里收集一些数据时,需要 HTML 表单。当您只想从多个可用选项中选择一个选项时,可以使用单选按钮。
例子:
Radio Button
输出:
复选框:复选框也主要用于 HTML 表单中。复选框允许您从选项列表中选择一个或多个选项。
例子:
HTML Checkbox
输出:
单选按钮和复选框的区别
Radio button | Checkbox |
---|---|
It is used when only one option to be selected out of several available options. | Checkbox allows one or many options to be selected. |
It is created by using HTML tag but type attribute is set to radio. | It is also created using HTML tag but type attribute is set to checkbox. |
It is a single control unit. | It is a multiple control unit. |
Radio button is presented as a small circle on the screen. | Checkbox is presented as a small square box on the screen. |
Radio button have only 2 states namely- True & False. | Checkbox have 3 states namely- Checked, unchecked & indeterminate. |
It is used when you want to limit the users choice to just one option from the range provided. | It is used when you want to allow user to select multiple choices. |