我正在通过几个"checkbox"类型的输入元素进行循环.之后,我将向数组添加值和已判断属性.这是我的代码:
var stuff = {};
$('form input[type=checkbox]').each(function() {
stuff[$(this).attr('value')] = $(this).attr('checked');
});
This works fine, but I'm just wondering if I can do the exact same thing with .push() method in Jquery?
I've tried something like this but it doesn't work:
stuff.push( {$(this).attr('value'):$(this).attr('checked')} );
Edit:
I was trying to use .push() method on Object, but .push() is actually just a method of Array Object.