簡體   English   中英

復選框在jQuery中啟用/禁用

[英]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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM