【发布时间】:2017-04-15 04:31:53
【问题描述】:
我想编写一个程序来通过 remove 属性 jQuery 代码来启用和禁用复选框上的按钮。
我试过了,但没用。
$(document).ready(function() {
$('#myCheckBox').on('change', function() {
var x = $(this).attr('value');
if (x == 'on') {
$('#myButton').removeAttr('disabled');
} else if (x == undefined) {
$('#myButton').attr('disabled');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<label for="myCheckBox">
I agree with terms and conditions
<input type="checkbox" id="myCheckBox" />
</label>
<br />
<br />
<input type="button" id="myButton" value="Submit" disabled />
我是 jQuery 初学者,如有任何疑问,请在下方评论。
【问题讨论】:
-
不要查询复选框的值,改用
.prop('checked')。 -
x==on???你确定 -
使用这个fiddle
标签: javascript jquery