简体   繁体   English

iCheck复选框作为单选按钮

[英]iCheck checkboxes as radio buttons

I'm using iCheck for radio buttons and checkboxes. 我正在使用iCheck收音机按钮和复选框。
How can I use checkboxes to act like radio buttons with iCheck? 如何使用复选框与iCheck一起使用单选按钮?

This is what I have: 这就是我所拥有的:

$j(function(){
    $j('input:checkbox.tip-facturare').on('ifChecked', function(event){
    $j('input:checkbox.tip-facturare').not($j(this)).iCheck('uncheck');
    $j(this).iCheck('check');
});

This works for me: 这对我有用:

$j('input:checkbox.tip-facturare').on('ifChecked', function(e){
    $j('input:checkbox.tip-facturare').not($j(this)).iCheck('uncheck').iCheck('enable');
    $j(this).iCheck('disable').parents('div').removeClass('disabled');
});

$j(document).on('mouseleave','.hover.checked', function() {
    $j(this).removeClass('hover');
});

Explanation if needed: 需要时说明:

Disabling the checkbox cleanly prevents user from unchecking, but makes it gray (per iCheck's '.checked.disabled' class). 清除禁用复选框可防止用户取消选中,但会将其设置为灰色(根据iCheck的'.checked.disabled'类)。 Doing .removeClass('disabled') on the parent div restores the color without having to hack the background position (iCheck uses one background image for all checkbox and radio states) and having to undo it later. 在父div上执行.removeClass('disabled')可以恢复颜色而不必破解背景位置(iCheck对所有复选框和无线电状态使用一个背景图像)并且必须稍后撤消它。 Another side-effect is the 'hover' class won't go away when you mouseout, presumably because it's now disabled, hence the extra mouseleave listener. 另一个副作用是当你鼠标移除时'hover'类不会消失,大概是因为它现在被禁用了,因此额外的mouseleave监听器。

Tested in the latest versions of Chrome, Firefox, and IE. 在最新版本的Chrome,Firefox和IE中测试过。
Well, I tested using '$', but I'm not using multiple JS libraries. 好吧,我测试使用'$',但我没有使用多个JS库。 Converted to $j for you. 转换为$ j为您服务。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM