jquery 中的复选框 enable/disable

checkbox enable/disable in 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>

为了检查复选框是否被选中,您可以这样做。如果你不能让它工作,请告诉我,我可以提供更多帮助。

$("#work").on("change", function(){
   var checked = $(this).is(':checked');
   if(checked){
       $("#idofwahteveryouwantdisabled").css("disabled", true);
   }
   else{
       $("#idofwahteveryouwantdisabled").css("disabled", false);
   }
}

$("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>