如何使复选框有和单选框一样的功能? 能用JS实现这样的功能吧? 谢谢了 麻烦了米分啊~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script>function check(obj){ var a = obj.form.elements[obj.name]; if(a.length) for(var i=0;i<a.length;i++) a[i].checked = false; obj.checked = true;} </script><form> <input type="checkbox" name="xx" onclick="check(this);"> <input type="checkbox" name="xx" onclick="check(this);"> <input type="checkbox" name="xx" onclick="check(this);"> <input type="checkbox" name="xx" onclick="check(this);"> <input type="checkbox" name="xx" onclick="check(this);"></form> 关键是 把复选框的name 设置为相同的 <html><head></head><body><form name="myForm"><input type="CheckBox" value="1" name="test" onclick="myFunction(this)">1<br><input type="CheckBox" value="2" name="test" onclick="myFunction(this)">2<br><input type="CheckBox" value="3" name="test" onclick="myFunction(this)">3<br><input type="text" name="mytext"></form><script type="text/javascript"> function myFunction(obj) { if(obj.checked) { for(i=0;i<document.myForm.test.length;i++) { if (document.myForm.test[i].value != obj.value) { document.myForm.test[i].checked = false; } } document.myForm.mytext.value = obj.value; } } </script></body> 字符串型的方法如何在js中执行 请教高手,js框架间获取事件问题 在Firefox上如何用代码实现全屏? 如何禁止javascript重定向跳出frame ********怎样让alert出来的信息包含超链接 我一打开总页面,怎么实现每个页面报警? 有段代码实在看不懂……请大家帮忙 关于按钮的问题,急,在线等待 怎么 在<area>标签里不可以所有onmouse处理事件 关于弹出窗口的控制 贪吃蛇 那个js charts 组件比较好?开源的
<script>
function check(obj){
var a = obj.form.elements[obj.name];
if(a.length) for(var i=0;i<a.length;i++) a[i].checked = false;
obj.checked = true;
}
</script>
<form>
<input type="checkbox" name="xx" onclick="check(this);">
<input type="checkbox" name="xx" onclick="check(this);">
<input type="checkbox" name="xx" onclick="check(this);">
<input type="checkbox" name="xx" onclick="check(this);">
<input type="checkbox" name="xx" onclick="check(this);">
</form>
<head></head>
<body>
<form name="myForm">
<input type="CheckBox" value="1" name="test" onclick="myFunction(this)">1<br>
<input type="CheckBox" value="2" name="test" onclick="myFunction(this)">2<br>
<input type="CheckBox" value="3" name="test" onclick="myFunction(this)">3<br><input type="text" name="mytext">
</form>
<script type="text/javascript">
function myFunction(obj)
{
if(obj.checked)
{
for(i=0;i<document.myForm.test.length;i++)
{
if (document.myForm.test[i].value != obj.value)
{
document.myForm.test[i].checked = false;
}
}
document.myForm.mytext.value = obj.value;
}
} </script>
</body>