我正在使用 Jquery iCheck 来设置输入字段的样式,但我到了无法真正处理来自 iCheck 的回调的地步。我要检索的内容是具有给定类名的容器内的所有检查输入值
http://jsfiddle.net/lgtsfiddler/E4bKg/1/ 这是我一直在尝试的,但是在第二次点击时,点击的流上的元素不会被推送到数组中。
<ul class="brands">
<li>
<input class ="marken" type="checkbox" name="brand" value="brand1">
<label>brand1</label>
</li>
<li>
<input class ="marken" type="checkbox" name="brand" value="brand1">
<label>brand2</label>
</li>
<li>
<input class ="marken" type="checkbox" name="brand" value="brand1">
<label>brand3</label>
</li>
<li>
<input class ="marken" type="checkbox" name="brand" value="brand1">
<label>brand4</label>
</li>
</ul>
代码:
$(document).ready(function () {
//here I style with iCheck
$('ul.brands input').each(function () {
var self = $(this),
label = self.next(),
label_text = label.text();
label.remove();
self.iCheck({
checkboxClass: 'icheckbox_line-blue',
radioClass: 'iradio_line',
insert: '<div class="icheck_line-icon"></div>' + label_text
});
});
//Register click event
$('ul.brands input').on('ifClicked', function (event) {
brands();
});
});
//here I try to retrieve all checked values
function brands() {
var brands = [];
$('ul.brands li div.icheckbox_line-blue').each(function (index, value) {
var attr_class = $(value).attr('class');
console.log(attr_class);
//check if icheckbox_line-blue class contains checked
if (attr_class.indexOf("checked") !== -1) {
brands.push($(value).find('input').val());
}
});
console.log(brands);
}
那么在检查后如何检查这个类?