Show/hide input field based on checkbox [duplicate]

≯℡__Kan透↙ 提交于 2020-01-07 04:32:06

问题


If the checkbox is clicked it will display an input field... so far it it is working, But if the checkbox is unchecked it should hide it, how can i do it?

    <div class="checkbox"> 
    <label class="checkbox-custom"> 
    <input type="checkbox" name="clases" id="clases" value="yes">
    <i class="fa fa-fw fa-square-o"></i> Doy clases particulares/grupales
    </label> 
    </div>


    <div class="input" id="descripcion">
    <label for="exampleInputEmail1">Descripcion</label>
   <textarea type="textarea" rows="7" cols="" class="form-control"  name="descripcion" placeholder="" required></textarea>
    </div>

Here is the script

    <script type="text/javascript">
    $(document).ready(function () {
     $("#descripcion").hide();
    $("#clases").click(function () {
    $("#descripcion").show();
    });
    });
    </script>  

回答1:


$("#clases").change(function () {
   $("#descripcion").toggle();
});


来源:https://stackoverflow.com/questions/25853803/show-hide-input-field-based-on-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!