iCheck jQuery阻止自定义脚本 [英] iCheck jQuery blocks custom script

查看:90
本文介绍了iCheck jQuery阻止自定义脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用"iCheck jQuery"来修改复选框的样式.但是,当我添加iCheck脚本时-我的onlick脚架停止工作.为什么会发生?

I used "iCheck jQuery" to modificate the style of the checkbox. But when i add a iCheck script - my onlick metod stops working. Why it happening?

<input id="my_cb"  type="checkbox" value="yes_n" onclick="hide_row_metod()"/>
    <script>
    $(document).ready(function(){
      $('#my_cb').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
      });
    });    
    </script>

我的脚本:

<script>
   function hide_row_metod() {
     if(document.getElementById('my_cb').checked){
        document.getElementById('row1').style.display = "none";
     }else{
            document.getElementById('row1').style.display = "inline";
          }
     }
</script>

推荐答案

iCheck 注册可以监听的自定义事件.我在jsbin上放置了一个工作示例,主要区别是:

$("#my_cb").on("ifChanged", hide_row_metod);

有两个事件: ifCheckedifUnchecked .如果要捕获对复选框的所有更改,则需要同时侦听这两者或仅侦听ifChanged.在测试hide_row_metod中的checked时,这将用于切换行.

There are two events: ifChecked and ifUnchecked. If you want to catch all changes to your checkbox, you need to either listen for both or simply listen for ifChanged. This will work to toggle the row, as you are testing for checked in your hide_row_metod.

在我的示例中,我使用了一个块元素div#row1,因此在选中和取消选中之后,它会呈现不同的外观(inline).

In my example, I use a block element div#row1, so it will render differently (inline) after checking and unchecking.

此外:您的方法名称中有一个错字(缺少h).

Also: you got a typo in your method name (missing h).

这篇关于iCheck jQuery阻止自定义脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆