【发布时间】:2014-06-02 18:19:01
【问题描述】:
所以我想禁用输入按钮功能,除非选中复选框。我不想要一个特定的复选框,但如果选中一个复选框或多个复选框,则该按钮(即删除按钮)将被启用。我遇到的问题是删除按钮仅在选中第一个复选框时才启用。例如,第二个或第三个复选框被选中,删除按钮仍然被禁用,除非第一个复选框也被选中。
有没有办法解决这个问题?
按钮:
<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");
}
});
感谢任何帮助。
【问题讨论】:
-
#check作为标识符是您的主要问题 -id应该是完全唯一的:页面中只有一个元素。
标签: javascript php button checkbox input