【问题标题】:display the inputbox based on checkbox state by jquery append通过jquery append根据复选框状态显示输入框
【发布时间】:2017-04-25 10:51:42
【问题描述】:

我想根据复选框状态隐藏和显示输入框。在我的情况下,两者都由 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>');

请给我任何可能的建议。

【问题讨论】:

    标签: checkbox append show-hide inputbox


    【解决方案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>
    
        

    【讨论】:

    • 感谢@Ghanshyam Bhava 的回答,它是在html 中显示的代码。但是我想在 jquery 附加的 html 时做同样的事情
    • @Naresh,检查更新的 sn-p。可能正是你想要的!
    猜你喜欢
    • 2016-02-16
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多