2017-04-25 77 views
-2

我想根据复选框状态隐藏和显示输入框。在我的情况下,这两个jquery追加如下:显示基于复选框状态的输入框由jquery追加

$container.append('<li><label><input type="checkbox" style="float:left"</label> 
<input type="text" name="couple_answers['+index+']" id="couple_answers_'+index+'" maxlength="500" class="input-item form-control text-field"></li>'); 

请建议我任何可能性。

回答

1

$(function(){ 
 
    $('#chk').on('change',function(){ 
 
     if(this.checked) { 
 
      $('#res').html("<input id='inp' type='text' />"); 
 
     }else{ 
 
      $('#inp').hide(); 
 
     } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form> 
 
    <input type="checkbox" id="chk" checked/> Click Here  
 
    <br/><br/> 
 
    <div id="res"></div> 
 
</form> 
 

 

+0

感谢您的回答@Ghanshyam巴瓦,它是在HTML中显示的代码。但我想要做的一样,而附加的jquery – Naresh

+0

@Naresh,检查更新的片段的HTML。可能是你想要的! –