【发布时间】:2016-03-09 11:38:09
【问题描述】:
如果没有选中checkbox,我想禁用我的button。至少应选中一个checkbox 以启用该按钮。
我的 HTML:
<table border="1">
<tr>
<th></th>
<th>Name</th>
</tr>
@foreach($clients as $client)
<tr>
<td><input type="checkbox" name="status[]" value="$client['id']" class="checkbox"></td>
<td>{{ $client['name'] }}</td>
</tr>
@endforeach
</table>
<button type="button" id="off" class="btn btn-default" data-toggle="modal" data-target="#offer" disabled>Choose New Offer</button>
我试过这个 jQuery 代码:
<script>
$(function() {
$('.checkbox').click(function() {
if ($(this).is(':checked')) {
$('#off').removeAttr('disabled');
} else {
$('#off').attr('disabled', 'disabled');
}
});
});
</script>
按钮默认为disabled。检查一个复选框时,它已启用,当未选中它已再次禁用。但问题是当我选中多个复选框并取消选中一个复选框时,它再次被禁用,尽管许多复选框仍然被选中。
【问题讨论】:
标签: javascript jquery html button checkbox