【问题标题】:can anyone help me with this problem about radio button谁能帮我解决这个关于单选按钮的问题
【发布时间】:2023-01-25 18:38:05
【问题描述】:
当我运行这段代码时,它不是一个单选按钮,就像我可以单击所有 2 按钮并且我无法删除单击
<!DOCTYPE html> <html> <title>abc</title> <body> <h1>Input Form</h1> <form action="abc"> <input type="radio">abc <input type="radio">hwqwhdwq </form> </body> </html>
我是一名高中生,我正在尝试 udemy 的一些课程并遇到这个问题。我希望有人能帮我弄清楚我错在哪里
【问题讨论】:
标签:
html
css
button
radio-button
radio
【解决方案1】:
如果我理解你的话,我想你只是想选择一个单选框而不是两个都对吗?如果是,那么这是如何做到的,添加 name="" 属性并为它们设置相同的名称。
<body>
<h1>Input Form</h1>
<form action="abc"> <input type="radio" name="btn">abc <input type="radio" name="btn">hwqwhdwq </form>
</body>
【解决方案2】:
i think you have to do this
<!DOCTYPE html>
<html>
<head>
<title>abc</title>
</head>
<body>
<h1>Input Form</h1>
<form action="abc">
<label for="radio1"><input type="radio" name="radioBtn" id="radio1"> Radio 1</label>
<label for="radio2"><input type="radio" name="radioBtn" id="radio2"> Radio 2</label>
</form>
</body>
</html>