简体   繁体   English

在iCheck的复选框上显示和隐藏另一个复选框处于选中和未选中状态

[英]Show And Hide Another Checkbox on iCheck's checkbox checked and unchecked state

Here is my code 这是我的代码

Icheck checkbox css class mapping code icheck复选框CSS类映射代码

<script>
$(function () {
    //Initialize Select2 Elements
    $(".select2").select2();        
    //Flat red color scheme for iCheck
    $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
        checkboxClass: 'icheckbox_flat-red',
        radioClass: 'iradio_flat-red'
    });

});

Jquery for Showing and hiding second checkbox 显示和隐藏第二个复选框的jQuery

<script>
$("#ch_bx_haveparent").iCheck('toggle', function () {
    $("#ch_bx_haveparent").on('ifChecked', function (event) {
        alert('ch_bx_status Checkbox Shown');
        $("#ch_bx_status").show();
    });
    $("#ch_bx_haveparent").on('ifUnchecked', function (event) {
        alert('ch_bx_status Checkbox  hidden');
        $("#ch_bx_status").hide();
    });
});

click here for Icheck Checkbox 单击此处查看Icheck复选框

HTML Code HTML代码

<div class="modal" id="menuiconmodal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Menu</h4>
          </div>
          <div class="modal-body"> 

       <div class="form-group"><input type="checkbox" class="flat-red" id="ch_bx_haveparent"/> 
       // Input tag for checkbox that will be shown and hidden
       <div class="form-group"><input type="checkbox" class="flat-red" runat="server" id="ch_bx_status" /></div>
       </div>
          </div>
          <div class="modal-footer">

            <a href="javascript:;" id="sucess" class="btn btn-primary" data-dismiss="modal">Save</a>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>  
    <!-- /.modal -->

Alert is populating but Hiding and showing is not working. 警报正在填充,但是隐藏和显示不起作用。

 $("#ch_bx_haveparent").change(function() { if ($("#ch_bx_haveparent").is(':checked')) { $("#ch_bx_status").show(); } else { $("#ch_bx_status").hide(); } }).change(); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="modal" id="menuiconmodal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> <h4 class="modal-title">Menu</h4> </div> <div class="modal-body"> <div class="form-group"> <input type="checkbox" class="flat-red" id="ch_bx_haveparent" />// Input tag for checkbox that will be shown and hidden <div class="form-group"> <input type="checkbox" class="flat-red" runat="server" id="ch_bx_status" /> </div> </div> </div> <div class="modal-footer"> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> 

Try this way 试试这个

$('#ch_bx_haveparent').change(function () {
    if ($(this).attr("checked")) {
        $("#ch_bx_status").show();
        return;
    }
    $("#ch_bx_status").hide();
});

**Found Solution with jquery's addClass() and removeClass() Methods for icheck checkbox hiding and showing in ** **使用jquery的addClass()和removeClass()方法创建解决方案,用于icheck复选框隐藏并显示在其中**

Code of CSS CSS代码

.call
    {
        display:none;
    }

Code of Jquery jQuery的代码

<script>
$("#ch_bx_haveparent").iCheck('toggle', function () {
    $("#ch_bx_haveparent").on('ifChecked', function (event) {
        $("#parentmenu").removeClass("call"); // hide

    });
    $("#ch_bx_haveparent").on('ifUnchecked', function (event) {
        $("#parentmenu").addClass("call"); // shown
    });
});

**Where div id="parentmenu" ** **其中div id =“ parentmenu” **

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript隐藏/显示div复选框:选中/取消选中 - javascript Hide/show div on checkbox: checked/unchecked 在复选框上显示/隐藏表单字段已选中/未选中 - Show/Hide Form Fields on checkbox checked/unchecked 如何在选中复选框时隐藏内容并在未选中复选框时显示? - How to hide content when checkbox is checked and show when checkbox is unchecked? iCheck 检查复选框是否被选中 - iCheck check if checkbox is checked 选中/取消选中复选框时如何隐藏/显示内容? - How to hide/show content when checkbox is checked/unchecked? 选中/取消选中复选框时如何隐藏/显示表单的一部分? - How to hide/show part of a form when checkbox is checked/unchecked? 如何显示/隐藏<div>什么时候<mat-checkbox>被选中/未选中? - How to show/hide <div> when <mat-checkbox> is checked/unchecked? 如何使用jQuery在复选框的选中/未选中状态上显示/隐藏元素 - How to show/hide an element on checkbox checked/unchecked states using jQuery 选中复选框时,jQuery隐藏div,未选中时显示 - jQuery hide div when checkbox checked, show on unchecked 使用涉及“ checkbox.checked === true”的if / then命令在涉及另一个复选框时隐藏/显示元素时出现问题 - Problem using if/then command with “checkbox.checked === true” to hide/show an element when there's another checkbox involved
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM