页面代码为:
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" onclick="getemlemtID(this);" value="1"/>
</label>
1
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="1" />
</label>
1</p>
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" value="2" onclick="getemlemtID(this);"/>
</label>
2
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="2" />
</label>
2
</p>
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" value="3" onclick="getemlemtID(this);"/>
</label>
3
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="3" />
</label>
3
</p>
</form>
我想点击checkbox值为1的复选框,checkbox1值为1的复选框也选中?
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" onclick="getemlemtID(this);" value="1"/>
</label>
1
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="1" />
</label>
1</p>
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" value="2" onclick="getemlemtID(this);"/>
</label>
2
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="2" />
</label>
2
</p>
<p>
<label>
<input name="checkbox" type="checkbox" id="checkbox" value="3" onclick="getemlemtID(this);"/>
</label>
3
<label>
<input name="checkbox1" type="checkbox" id="checkbox1" value="3" />
</label>
3
</p>
</form>
我想点击checkbox值为1的复选框,checkbox1值为1的复选框也选中?
{
if obj.value==1
if(document.getElementById("checkbox1").value==1)
document.getElementById("checkbox1").checkd=true;
}
这是个伪代码,我写了个大概意思。本机太慢了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
var length = $(".checkbox").length;
//alert(length)
$(".checkbox").change(function(){
var $checkbox1 = $(this).parent().next().children(".checkbox1");
if($(this).is(":checked")){
$checkbox1.attr("checked",true);
}else{
$checkbox1.attr("checked",false);
}
});
$(".checkbox1").change(function(){
var $checkbox = $(this).parent().prev().children(".checkbox");
if($(this).is(":checked")){
$checkbox.attr("checked",true);
}else{
$checkbox.attr("checked",false);
}
}); });</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input name="checkbox" type="checkbox" class="checkbox" onclick="getemlemtID(this);" value="1"/>
</label>
1
<label>
<input name="checkbox1" type="checkbox" class="checkbox1" value="1" />
</label>
1</p>
<p>
<label>
<input name="checkbox" type="checkbox" class="checkbox" value="2" onclick="getemlemtID(this);"/>
</label>
2
<label>
<input name="checkbox1" type="checkbox" class="checkbox1" value="2" />
</label>
2
</p>
<p>
<label>
<input name="checkbox" type="checkbox" class="checkbox" value="3" onclick="getemlemtID(this);"/>
</label>
3
<label>
<input name="checkbox1" type="checkbox" class="checkbox1" value="3" />
</label>
3
</p>
</form>
</body>
</html>