在我的phonegap应用程序中,我使用jquery mobile
。当从我的数据库检索值
时,其他字段都已正确填写(文本框值已正确填写
),除了复选框
之外。我的问题是,当数据库返回 true 或 false
时,无论它是什么,我的复选框都没有变化
。我为这个问题苦苦挣扎了两天,有人建议解决这个问题的解决方案..
我的编码是这样的:
if (results.rows.item(0).checkbox1 == true)
$("#checkbox1").attr('checked', 'checked');
else $("#checkbox1").removeAttr('checked');
也尝试过这个:
//$('#checkbox1').prop('checked', true).checkboxradio('refresh');
//$("input[id='checkbox1']").attr("checked",results.rows.item(0).checkbox1).checkboxradio("refresh");
已解决: 喜欢
if (results.rows.item(0).checkbox1 === 'true')
$("#checkbox1").attr('checked', 'checked');
else $("#checkbox1").removeAttr('checked');
最佳答案
试试这个:
var dbValue = (results.rows.item(0).checkbox1 === true);
$('#checkbox1').prop('checked', dbValue);
注意第一行中的===。如果您的数据库返回值类似于 1 或字符串“true”,请明确检查它。
关于javascript - 从数据库检索值时未选中 Jquery mobile 复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20268041/