我目前正在使用:
- remodalJS 0.6.4
- iCheckJS 1.0.2
UX 的设计使 iCheck 复选框和收音机充当过滤器并存在于 remodal 中。当我将这两个库配对使用时,发生了奇怪的事情:
这是 Chrome 的控制台输出,
ifChecked
选中选择(通过无线电或复选框)时,要多一次射击一次。
<html>
<head>
<link rel="stylesheet" href="bower_components/remodal/dist/jquery.remodal.css">
<link rel="stylesheet" href="bower_components/iCheck/skins/line/green.css">
</head>
<body>
<h1 data-remodal-target="test-icheck-remodal"> Animal</h1>
<h1 data-remodal-target="test-icheck-remodal-2"> Comics</h1>
<div class="remodal" data-remodal-id="test-icheck-remodal">
<h2>Choose Animal</h2>
<input type="checkbox" value="">
<label>Cat</label>
<input type="checkbox" value="">
<label>Dog</label>
</div>
<div class="remodal" data-remodal-id="test-icheck-remodal-2">
<h2>Choose Comics</h2>
<input type="checkbox" value="">
<label>Batman</label>
<input type="checkbox" value="">
<label>Superman</label>
</div>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/remodal/dist/jquery.remodal.js"></script>
<script type="text/javascript" src="bower_components/iCheck/icheck.js"></script>
<script type="text/javascript">
$('input:checkbox, input:radio').each(function() {
var self = $(this),
label = self.next(),
label_text = label.text();
label.remove();
self.iCheck({
checkboxClass: 'icheckbox_line-green',
radioClass: 'iradio_line-green',
insert: '<div class="icheck_line-icon"></div>' + label_text
})
});
var flag = false;
$(document).on('open', '.remodal', function(e) {
var $this = $(this);
var inputFields = $this.find('input:checkbox, input:radio');
console.log('remodal Opened');
if(!flag) {
inputFields.on('ifChecked', function(event) {
console.log('ifChecked called');
});
flag = true;
}
});
</script>
</body>
</html>
对应的 bower.json
{
"name": "remodal_icheck",
"version": "0.0.0",
"dependencies": {
"remodal": "0.6.4",
"iCheck": "1.0.2"
},
"devDependencies": {
}
}