我正在尝试这样做。JavaScript启用禁用单选按钮,并一次只选择一个
我有3个单选按钮,
- 如果在一个电台点击它的设置,下一次我点击它。它应该 未经检查/休息。
我想在没有jquery的标准javascript中做,因为目前还不能。
这是我的代码到目前为止。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function toggle(radioBtn)
{
if(radioBtn.checked)
{
radioBtn.checked = false;
}
else
{
radioBtn.checked = true;
}
// only select one at a time.
}
</script>
</head>
<body>
<form id="myForm" name="myForm">
<input type="radio" name="radioBtn" id="radioBtn1" value="A" onClick="toggle(this);" />
<input type="radio" name="radioBtn" id="radioBtn1" value="B" onClick="toggle(this);"/>
<input type="radio" name="radioBtn" id="radioBtn1" value="C" onClick="toggle(this);"/>
</form>
</body>
</html>
请大家帮忙。您的帮助将不胜感激。 感谢
共享相同“名称”属性的单选按钮将由浏览器管理,因此无法设置多个按钮。换句话说,我不明白你为什么需要代码来做到这一点。 – Pointy
@Pointy,谢谢。你现在正想要另一部分。切换单选按钮。我怎样才能做到这一点。 – Nomad
你不能设置多个单选按钮。您必须使用复选框。 –