<!DOCTYPE html>
<html>
<head>
<title>HTML Radio Example</title>
</head>
<body>
<form action="">
<fieldset>
<legend>Select your favorite fruit:</legend>
<!-- Radio buttons are used to select one option from a set of options -->
<input type="radio" id="apple" name="fruit" value="apple">
<label for="apple">Apple</label><br>
<input type="radio" id="banana" name="fruit" value="banana">
<label for="banana">Banana</label><br>
<input type="radio" id="orange" name="fruit" value="orange">
<label for="orange">Orange</label><br>
<input type="submit" value="Submit">
</fieldset>
</form>
</body>
</html>
<input type="radio">
:用于创建单选按钮。用户只能从一组单选按钮中选择一个选项。name
属性:确保所有相关的单选按钮具有相同的 name
值,以便它们被视为一组,用户只能选择其中一个。id
和 for
属性:id
用于标识每个单选按钮,for
属性用于将标签与单选按钮关联起来,点击标签时也会选中对应的单选按钮。value
属性:定义了当表单提交时,所选单选按钮的值。希望这个示例能帮助你理解如何使用 HTML 中的单选按钮!
上一篇:html居中代码
下一篇:html checkbox
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站