检查是否选中了JQuery mobile复选框

我有一个复选框列表,我想获得每个复选框的状态。 清单在这里:

我通常使用此引号检查复选框的状态:

var isChecked = $('#CheckboxID').is(':checked');

但在我的情况下,是否有一种方法可以同时获取“Jquery Mobile”复选框的状态?

你可以做

 var status = $('input[type="checkbox"]').filter('.custom').map(function(){ return $(this).is(':checked') ? 1 : 0; }); 

然后status array将以相同的顺序为每个复选框提供一个条目, 0表示未选中, 1表示已选中。 它没有多大用处,因为你没有关于数组中复选框的其他信息。

如果你想根据status执行操作,你可以使用.each()代替

 $('input[type="checkbox"]').filter('.custom').each(function(){ if($(this).is(':checked')){ // perform operation for checked } else{ // perform operation for unchecked } }); 

UPDATE

如果要构建具有复选框name and statusarray of objects可以使用

 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/

阅读.each().map()

我有这个代码。 我认为你应该适应你的情况。

  $('#formfriends input[type=checkbox]').each(function() { if ($(this).attr('checked')) //$(this).attr('disabled' , true); // do what you want here }); 

你可以使用jQuery的每个函数http://api.jquery.com/jQuery.each/

.each函数将帮助您遍历复选框

对于jQm 1.3,我必须检查包装器div中标签上的类

  • UI的复选框关闭
  • UI的复选框上

samplecode(已由jQm呈现):