【发布时间】:2018-10-10 04:16:16
【问题描述】:
我有一个复选框列表,并且基于至少一个选择,需要启用或禁用一个按钮。
复选框具有名称,因为它们需要将值回发到服务器。
这是我试过的代码:
$('input').change(function() {
console.log('cheeck box change');
if ($("input[name='name1']:checked").length) {
$('#sub').removeAttr('disabled');
} else {
$('#sub').attr('disabled', 'disabled');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p><input type='checkbox' class='check'> Value</p>
<p><input type='checkbox' class='check'> Value</p>
<p><input type='checkbox' class='check'> Value</p>
<p><input type='checkbox' class='check'> Value</p>
<p><input type='checkbox' class='check'> Value</p>
<input id='sub' type='button' value='Submit' disabled='disabled'>
【问题讨论】:
-
@ChintuYadavSara,这款时尚。你能把这个添加到答案中吗?
-
这不是我的工作,它的 @chris-coyier ,所以我不能将其添加为我的答案。 :) 我刚在网上找到它
-
@ChintuYadavSara,感谢您的诚实。您仍然可以在答案中注明来源。但这真的会帮助任何来到这篇文章的人
标签: javascript jquery html validation