<html>
<head>
<script language=javascript>
function a(c){
if(c.checked){
if(c.value==1){
document.all.a.disabled=false;
}
else{
document.all.a.disabled=true;
}
}else{
document.all.a.disabled=!document.all.a.disabled;
}
}
</script>
</head>
<body >
<input type="button" name="a"  value="delete"  >
<input type="checkbox" name="element1" value="1"  onclick="a(this);" > abc
<input type="checkbox" name="element1" value="2"  onclick="a(this);" >def</body>
</html>

解决方案 »

  1.   

    这种用radio 比较好控制一点
      

  2.   

    我想要实现的效果是这样的。从Action中返回到这个页面。由后台传过来的值决定checkbox是否有被选中的。同时,想要初始化按钮的有效无效,如果checkbox有被选中的,则按钮有效,否则默认无效。
      

  3.   

    <html>
    <head>
    <script language=javascript>
    function a(c){

    var o=document.all.element1;
    if(o!=null && o.length>0){
    if(o[0].checked){
    document.all.a.disabled=true;
    }
    if(o[1].checked){
      document.all.a.disabled=false;
    }

    }
    }
    </script>
    </head>
    <body onload="a();" >
    <input type="button" name="a"  value="delete"  >
    <input type="checkbox" name="element1" value="1"   > abc
    <input type="checkbox" name="element1" value="2"  checked  >def</body>
    </html>