复选框启用/禁用jquery
问题描述:
我想启用输入表单时,我检查输入复选框。复选框启用/禁用jquery
<div class="form-group clearfix">
<input type="checkbox" id="work" class="pull-left" />
<label for="work" class="form-info pull-left">
{!! Form::number('work', null, ['class' => 'form-control work','placeholder' => 'Nghề nghiệp'])!!}
</label>
</div>
<div class="form-group clearfix">
<input type="checkbox" id="city" class="pull-left" />
<label for="city" class="form-info pull-left">
{!! Form::number('city', null, ['class' => 'form-control city','placeholder' => 'Thành phố'])!!}
</label>
</div>
答
当你说启用/禁用
$("input[type=checkbox]").on("click",function(){
$("label[for="+$(this).attr("id")+"]").find("input[type=text]").prop("disabled", (!$(this).is(":checked")));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group clearfix">
<input type="checkbox" id="work" class="pull-left" />
<label for="work" class="form-info pull-left">
<input type="text" disabled />
</label>
</div>
<div class="form-group clearfix">
<input type="checkbox" id="city" class="pull-left" />
<label for="city" class="form-info pull-left">
<input type="text" disabled />
</label>
</div>
答
为了检查复选框是否被选中,你可以做什么这样的事情。如果你不能让它工作,让我知道,我可以帮助更多。
$("#work").on("change", function(){
var checked = $(this).is(':checked');
if(checked){
$("#idofwahteveryouwantdisabled").css("disabled", true);
}
else{
$("#idofwahteveryouwantdisabled").css("disabled", false);
}
}
,你的意思是不可点击字面上禁用?禁用表单元素将阻止它在提交时处理,我会显示/隐藏 – clearshot66