[英]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">×</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">×</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.