选中复选框时启用按钮 [英] Enable button when checkboxes selected
本文介绍了选中复选框时启用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个复选框和最初禁用的提交按钮。当选中一个框时,该按钮被启用,当取消选中时,该按钮被再次禁用。
如果选中了多个复选框,但取消选中了一个复选框,即使选中了其他复选框,该按钮也会被禁用。如何解决这个问题?
< script type =text / javascript>
$(function(){
$(。checkbox)。click(function(){
$(。delete)。attr(disabled,!this.checked );
});
});
< / script>
HTML
< input type =checkboxname =msg []value =32class =checkbox/>
< input type =checkboxname =msg []value =44class =checkbox/>
< input type =checkboxname =msg []value =26class =checkbox/>
< button type =submitclass =deletedisabled =disabled>删除< / button>
解决方案
$( function(){
$(。checkbox)。click(function(){
$('。delete')。prop('disabled',$('input.checkbox:checked') .length == 0);
});
});
演示: http://jsfiddle.net/AlienWebguy/3U364/
I have multiple checkboxes and a submit button that is initially disabled. When checking a box the button is enabled and when unchecking, the button is disabled again.
If have multiple checkboxes selected but uncheck one, the button becomes disabled even though I have selected other checkboxes. How can I fix this issue?
<script type="text/javascript">
$(function() {
$(".checkbox").click(function() {
$(".delete").attr("disabled", !this.checked);
});
});
</script>
HTML
<input type="checkbox" name="msg[]" value="32" class="checkbox" />
<input type="checkbox" name="msg[]" value="44" class="checkbox" />
<input type="checkbox" name="msg[]" value="26" class="checkbox" />
<button type="submit" class="delete" disabled="disabled">Delete</button>
解决方案
$(function() {
$(".checkbox").click(function(){
$('.delete').prop('disabled',$('input.checkbox:checked').length == 0);
});
});
Demo: http://jsfiddle.net/AlienWebguy/3U364/
这篇关于选中复选框时启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文