我现在有两个checkbox比如:<input type="checkbox" name="test" value="1" checked="checked"/>
<input type="checkbox" name="test" value="2"/>
value="1"的checkbox加载时默认选中,如果要实现我选中value=“2”的checkbox后,把第一个checkbox设为不选中,并且不能全都都为不选中状态,类似于radiobutton的规则,请给一个function,急,谢谢大虾。!身上真的没分了,忘见谅!!!jquerycheckbox
<input type="checkbox" name="test" value="2"/>
value="1"的checkbox加载时默认选中,如果要实现我选中value=“2”的checkbox后,把第一个checkbox设为不选中,并且不能全都都为不选中状态,类似于radiobutton的规则,请给一个function,急,谢谢大虾。!身上真的没分了,忘见谅!!!jquerycheckbox
解决方案 »
- <img>控件添加onclick()和mouseover()事件
- 怎么写search的函数。比如一个text框,然后onclick直接用百度search
- 急 在线等待!js问题 高手请进!
- javascript动态生成超链接传参数
- 新手看到一段简单代码,不理解?
- 请帮忙看看这个功能如何实现,
- 倒计时自动关闭窗口
- 100分求:javascript中调用application的方法
- 如果使用户只能输入大写字母和数字?
- 文本框中有没有办法实现即时触发判断输入值条件
- -------------------------菜鸟来学习,大神来指教----------关于js函数调用的问题
- Ext.window.Window close问题
$("input[type='checkbox'][name='test']").click(function () {
$(this).attr("checked", "checked").siblings().removeAttr("checked");
});
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
var ins=document.getElementsByTagName("input");
var arr=[];
for(var i=0;i<ins.length;i++){
if(ins[i].getAttribute('name')=='test'){
arr.push(ins[i]);
}
}
var l=arr.length;
for(var i=0;i<l;i++){
(function(m){
arr[m].onclick=function(){
if(this.checked){
for(var j=0;j<l;j++){
if(arr[j]!=this){
arr[j].checked=false;
}
}
}else{
arr[(m+1)%l].checked=true; }
}
})(i)
}
}
</script>
</head><body>
<input type="checkbox" name="test" value="1" checked="checked"/>
<input type="checkbox" name="test" value="2"/>
<input type="checkbox" name="test" value="3"/>
</body>
</html>
这样试试