我有一个 chekbox 和一个文本框<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"><input class="form-control" type="text" id="usr_zipcode" maxlength="10" name="usr_zipcode" required="required">如何制作 jquery,当 vehiche1 被选中但 usr_zipcode 为空或没有值时,它禁用另一个复选框,名称 checkme :<input type="checkbox" id="checkme">我尝试使用下面的代码但不起作用$('#vehicle1').change(function () { var input1 = $('#usr_zipcode'); input1.change( function() { var empty = ( input1.val() == '' ); $("#checkme").prop('checked', false); $("#checkme").attr('disabled','disabled'); });}).change();
2 回答

缥缈止盈
TA贡献2041条经验 获得超4个赞
创建一个单独的函数来检查或禁用另一个复选框,如下所示
function checkOrDisableAnotherCheckBox() {
if($('#vehicle1').is(':checked') && $('#usr_zipcode').val() == ''){
$("#checkme").attr('disabled', true);
} else {
$("#checkme").removeAttr('disabled');
}
}
$('#vehicle1').change(function () {
checkOrDisableAnotherCheckBox();
});
$('#usr_zipcode').keyup(function () {
checkOrDisableAnotherCheckBox();
});
添加回答
举报
0/150
提交
取消