Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用输入按钮,除非选中复选框_Javascript_Php_Button_Checkbox_Input - Fatal编程技术网

Javascript 禁用输入按钮,除非选中复选框

Javascript 禁用输入按钮,除非选中复选框,javascript,php,button,checkbox,input,Javascript,Php,Button,Checkbox,Input,所以我想禁用输入按钮功能,除非选中复选框。我不想要一个特定的复选框,但如果选中一个复选框或多个复选框,则该按钮(即删除按钮)将被启用。我遇到的问题是,删除按钮只有在选中第一个复选框时才启用。例如,如果选中了第二个或第三个复选框,则删除按钮仍处于禁用状态,除非选中了第一个复选框 有办法解决这个问题吗 按钮: <input type="submit" id="del_event" name="del_event" value="Delete Event"/> 感谢您的帮助。更改复选

所以我想禁用输入按钮功能,除非选中复选框。我不想要一个特定的复选框,但如果选中一个复选框或多个复选框,则该按钮(即删除按钮)将被启用。我遇到的问题是,删除按钮只有在选中第一个复选框时才启用。例如,如果选中了第二个或第三个复选框,则删除按钮仍处于禁用状态,除非选中了第一个复选框

有办法解决这个问题吗

按钮:

  <input type="submit" id="del_event" name="del_event" value="Delete Event"/>

感谢您的帮助。

更改复选框生成的代码,如下所示:

 echo 
   "<tr>
    <td><input type='checkbox' name='check' class='check'/><a href='' class='event-link'>$name</a>  
    </td><td>$date</td><td>$time</td><td>$venue</td>
  </tr>";
#检查
,因为标识符是您的主要问题-一个
id
应该是完全唯一的:一个页面中只有一个元素。
   var chkbox = $("#check"),
            button = $("#del_event");
       button.attr("disabled","disabled");
        chkbox.change(function(){
            if(this.checked){
                button.removeAttr("disabled");
            }else{
                button.attr("disabled","disabled");
            }
        });
 echo 
   "<tr>
    <td><input type='checkbox' name='check' class='check'/><a href='' class='event-link'>$name</a>  
    </td><td>$date</td><td>$time</td><td>$venue</td>
  </tr>";
       var chkbox = $(".check");
       button = $("#del_event");
       button.attr("disabled","disabled");
       chkbox.change(function(){
            if(this.checked){
                button.removeAttr("disabled");
            }else{
                button.attr("disabled","disabled");
            }
        });