日期:2014-05-16  浏览次数:20372 次

关于复选框绑定的问题
页面是jsp。
在页面中有2个复选框listbox   左边的名为   A,右边的为B,想在页面中绑定2个复选框,A选中的时候B也跟着变,不知道js中怎么绑定,数据是从数据库里提出来的如:A为(1,2,3,4   等)B为(a,b,c,d   等)

------解决方案--------------------
<input type= "checkbox " name= "a " value= "1 " onclick= "cl() ">
<input type= "checkbox " name= "a " value= "2 " onclick= "cl() ">
<input type= "checkbox " name= "a " value= "3 " onclick= "cl() ">
<input type= "checkbox " name= "a " value= "4 " onclick= "cl() ">
<input type= "checkbox " name= "b " value= "a ">
<input type= "checkbox " name= "b " value= "b ">
<input type= "checkbox " name= "b " value= "c ">
<input type= "checkbox " name= "b " value= "d ">

<script>
function cl()
{
o = document.getElementsByName( "a ");
for(c=0;c <o.length;c++)
{
document.getElementsByName( "b ")[c].checked = o[c].checked;
}
}
</script>
------解决方案--------------------
<form name= "autoSumForm " id= "form1 ">
<input type= "checkbox " name= "a " value= "1 " onclick= "cl( 'a ', 'b ') ">
<input type= "checkbox " name= "a " value= "2 " onclick= "cl( 'a ', 'b ') ">
<input type= "checkbox " name= "a " value= "3 " onclick= "cl( 'a ', 'b ') ">
<input type= "checkbox " name= "a " value= "4 " onclick= "cl( 'a ', 'b ') ">
<input type= "checkbox " name= "b " value= "a " onclick= "cl( 'b ', 'a ') ">
<input type= "checkbox " name= "b " value= "b " onclick= "cl( 'b ', 'a ') ">
<input type= "checkbox " name= "b " value= "c " onclick= "cl( 'b ', 'a ') ">
<input type= "checkbox " name= "b " value= "d " onclick= "cl( 'b ', 'a ') ">

<script>
function cl(a, b)
{
o = document.getElementsByName(a);
m = document.getElementsByName(b);
for(c = 0;c < o.length; c++)
{
m[c].checked = o[c].checked;
}
}
</script>
</form>
------解决方案--------------------
<select id= "a " onchange= "document.getElementById( 'b ').selectedIndex=this.selectedIndex ">
<option> 1 </option>
<option> 2 </option>
</select>
<select id= "b ">
<option> 1 </option>
<option> 2 </option>
</select>