简体   繁体   中英

checkbox enable/disable in jquery

I wanna enable input form when I check input checkbox.

<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>

In order to check if a checkbox is checked, what you can do somethig like this. if you can't get it working let me know and i can help more.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM