关于动态控制按钮的有效无效的小问题
button代码如下:
<input type= "button " name= "delete " class= "button1 " value= "delete "
disabled onclick= "button(this) " />
下面有一个checkbox,是否被选中由后台决定。
<logic:equal name= "a " property= "aa " value= " <%=packageCode%> ">
<input type= "checkbox " name= "element1 " value= "1 " checked >
</logic:equal>
<logic:notEqual name= "a " property= "aa " value= " <%=packageCode%> ">
<input type= "checkbox " name= "element1 " value= "1 ">
</logic:equal>
我现在想用JavaScript在前台实现这样的效果:
如果checkbox有被选中的,那么按钮为有效状态,如果没有被选中的,按钮为disabled。
不知道该如何实现,请高手指点,谢谢。
------解决方案-------------------- <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>