单选按钮无法正常工作

新手上路,请多包涵

在我的网页中,我放置了一些单选按钮。但是这些按钮不能正常工作。我可以检查多个按钮。

代码:

 <label for="abc" style="margin-top:-20px;margin-left:40px">xyz</label>
<input type="radio" id="abc" name="abc" >
<label for="bcd" style="margin-top:-20px;margin-left:40px">abc</label>
<input type="radio" id="bcd" name="bcd" >
<label for="efg" style="margin-top:-20px;margin-left:40px">ccc</label>
<input type="radio" id="efg" name="efg" >

小提琴

我只想检查一个按钮。请任何人帮助我。

原文由 James 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 308
2 个回答

因为您对 name 属性有不同的值,所以它们应该有一个共同的 name 值,就像您对项目进行分组一样。例如

<input type="radio" name="group1" />
<input type="radio" name="group1" />
<input type="radio" name="group1" />

<!-- You can select any one from each group -->

<input type="radio" name="group2" />
<input type="radio" name="group2" />
<input type="radio" name="group2" />

演示

原文由 Mr. Alien 发布,翻译遵循 CC BY-SA 3.0 许可协议

<label for="abc" style="margin-top:-20px;margin-left:40px">xyz</label>
<input type="radio" id="abc" name="abc" >
<label for="bcd" style="margin-top:-20px;margin-left:40px">abc</label>
<input type="radio" id="bcd" name="abc" >
<label for="efg" style="margin-top:-20px;margin-left:40px">ccc</label>
<input type="radio" id="efg" name="abc" >

所有输入必须具有相同的 name=“” 属性值

原文由 Different vision 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题