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


Disable input button unless checkbox is checked

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

有办法绕过这个吗?

按钮:

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

复选框被回显这是编码:

  echo 
   "<tr>
    <td><input type='checkbox' name='check' id='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");
            }
        });

任何帮助都将不胜感激。

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

 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>";

由于您要针对每个复选框启动此事件您需要在复选框中使用class而不是id。在jquery中:

       var chkbox = $(".check");
       button = $("#del_event");
       button.attr("disabled","disabled");
       chkbox.change(function(){
            if(this.checked){
                button.removeAttr("disabled");
            }else{
                button.attr("disabled","disabled");
            }
        });