如果复选框被选中,如何禁用文本框。 我有几个文本框和复选框彼此相邻。如果复选框被选中,jquery禁用下一个元素
HTML:
$("input[name=deposit_checked]").change(function(){
if($("input[name=deposit_checked]").is(":checked")) {
$("input[name=deposit_value]").attr("disabled", false);
} else {
$("input[name=deposit_value]").attr("disabled", true);
}
})
为了节省时间,我尝试使用。每()和的.next()函数,但没有运气:
<form id="form">
<input type="checkbox" name="deposit_checked"> <input type="text" name="deposit_value">
<input type="checkbox" name="booking_checked"> <input type="text" name="booking_value">
<input type="checkbox" name="referral_checked"> <input type="text" name="referral_value">
</form>
我可以用下面的代码单独做到这一点:
$("#form input[type=checkbox]").each(function() {
$(this).change(function(){
if($(this).is(":checked")) {
$(this).next().attr("disabled", false);
} else {
$(this).next().attr("disabled", true);
}
})
})
你的代码的工作,这是什么问题? – xdazz