0

尝试在单击另一个复选框时清除 2 个复选框。我已经搜索了这个答案,并尝试使用示例中的信息,但由于某种原因,我没有尝试任何工作。这是我目前正在使用的代码。

function control()
{
/*var one = document.getElementById('one');
var two = document.getElementById('two');
var three = document.getElementById('three');*/

if(document.forms[0].one.checked == true)
{
    document.forms[0].two.checked == false;
    document.forms[0].three.checked == false;
}

if(document.forms[0].two.checked == true)
{
    document.forms[0].three.checked == false;
    document.forms[0].one.checked == false;
}

if(document.forms[0].three.checked == true)
{
    document.forms[0].one.checked == false;
    docuemnt.forms[0].two.checked == false;
}
}
</SCRIPT>
</head>
<body>
<form action="" method="POST" name="getArea">
<input type="checkbox" onClick="control()" name="one">Standard Shipping<br />
<input type="checkbox" onClick="control()" name="two">Overnight Shipping<br />
<input type="checkbox" onClick="control()" name="three">Priority Shipping<br />
</form>
</body>
</html>
4

1 回答 1

0

你在尝试类似下面的东西吗?

<html>
<head>
 <script type="text/javascript">

function control(idSelected)
{
/*var one = document.getElementById('one');
var two = document.getElementById('two');
var three = document.getElementById('three');*/

if(idSelected==1)
{
    document.forms[0].two.checked = false;
    document.forms[0].three.checked = false;
}

if(idSelected==2)
{
    document.forms[0].three.checked = false;
    document.forms[0].one.checked = false;
}

if(idSelected==3)
{
    document.forms[0].one.checked = false;
    docuemnt.forms[0].two.checked = false;
}
}
</SCRIPT>
</head>
<body>
<form action="" method="POST" name="getArea">
<input type="checkbox" onClick="control(1)" name="one">Standard Shipping<br />
<input type="checkbox" onClick="control(2)" name="two">Overnight Shipping<br />
<input type="checkbox" onClick="control(3)" name="three">Priority Shipping<br />
</form>
</body>
</html>
于 2013-03-18T17:11:57.973 回答