更新时间:2023-11-30 19:31:10
但是在我的case现在,有没有一个方法来获取Jquery Mobile你可以做
You can do
var status = $('input[type="checkbox"]').filter('.custom').map(function(){
return $(this).is(':checked') ? 1 : 0;
});
然后状态数组
对于相同顺序的每个复选框,未检查的 0
和检查的 1
这不是很有用,因为你没有复选框的数组中的其他信息。
Then the status array
will have an entry for each checkbox in the same order, 0
for unchecked and 1
for checked. It's not much of useful as you have no other information of the checkbox in the array.
如果您要根据状态
执行操作,您可以使用 .each )
,如
If you want to perform operation based on the status
you can use .each()
instead, like
$('input[type="checkbox"]').filter('.custom').each(function(){
if($(this).is(':checked')){
// perform operation for checked
}
else{
// perform operation for unchecked
}
});
UPDATE
如果要使用复选框的名称和状态
构建对象数组
,您可以
If you want to build an array of objects
with the name and status
of the checkboxes you can do that with
var status = $('input[type="checkbox"]').filter('.custom').map(function(){
var name = $(this).attr('name');
if($(this).is(':checked'))
return { 'name':name, 'status' : 'Checked'};
else
return { 'name':name, 'status' : 'UnChecked'};
});
console.log(status);
演示: http://jsfiddle.net/joycse06/rL3Ze/
Read more on .each()
and .map()