icheck.js, ifChecked 事件触发不了, click 事件可以触发,是什么原因

2018-11-29 10:35:48 +08:00
 Y4ssss
<div class="radio">
  <label>
    <input type="radio" id="bargainSource_0" name="bargainSource" value="L"  checked>
    <span>1111</span>
  </label>
</div>
<div class="radio">
  <label>
    <input type="radio" id="bargainSource_1" name="bargainSource" value="B">
    <span>2222</span>
  </label>
</div>
                
$("input:radio[name='bargainSource']").on('ifChecked', function(event){
    alert('ifChecked');	
});

$("input:radio[name='bargainSource']").on('click', function(event){
    alert('click');
});

jquery 和 icheck 都已经引用,目前只能触发 click 事件,ifChecked 触发不了。
这是什么原因,刚开始接触 js,卡半天了。。。

6418 次点击
所在节点    JavaScript
6 条回复
chanchan
2018-11-29 10:54:35 +08:00
因为这是 radio?
Y4ssss
2018-11-29 11:03:42 +08:00
@chanchan icheck 的 demo 里,checkbox 和 radio 都可以用的
chanchan
2018-11-29 11:11:47 +08:00
因为没 class i-checks?
Y4ssss
2018-11-29 11:52:41 +08:00
@chanchan icheck.js 的 dome 中,web 加载后会在<input>后面添加一个<ins class="iCheck-helper" ></ins>。然后我在 ifChecked 事件后在加一个.iCheck()事件就可以触发 ifChecked 事件了
topsy
2018-11-29 16:55:59 +08:00
ifCreated callback should be binded before plugin init.
ifCreated 回调 需要 在 init 前绑定
@Y4ssss 与这个有关系吗?
Y4ssss
2018-11-29 17:17:03 +08:00
@topsy 没关系,就是要用 icheck 的除 ifCreated 之外的事件比如 ifChecked,要先用.iCheck () init 一下,比如:
$("input[type='checkbox'], input[type='radio']").iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue'
});
ifCreated 估计得在这之前先绑定。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/512624

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX