我有这些checkboxes我已经可以从它的表中获取值,但我只是不知道它最终会如何检查那些具有已插入我的数据库中的值的复选框。
function editPageLink(id){
$.ajax({
type : 'GET',
async : false,
data : {
key : id
},
url : baseUrl+'/admin/getdiscountinfo',
error: function(req,error){
notify('e',req.statusText);
},
dataType: 'json',
cache: false,
success : function(msg){
if(Object.keys(msg).length != 0){
newPage();
saveType = 'u';
key = msg[0].key;
$('#discountCode').val(msg[0].discountCode);
$('#discountName').val(msg[0].discountName);
$('#discountDesc').val(msg[0].discountDesc);
$('#discountType').val(msg[0].discountType);
$('#expiration').val(msg[0].expiration);
$('#expStartDate').val(msg[0].expStartDate);
$('#expEndDate').val(msg[0].expEndDate);
$('#discountValue').val(msg[0].discountValue);
$('#productId').val(msg[0].productId); if ('.chkbox2'.val() == true){
$('.chkbox2').check(checked); // i dunno if this is right.
};
$('#discounteTransaction').val(msg[0].discountTransaction);
}
}
});
我试过了,还是不行。感谢您的帮助! :D
编辑:我的#productId
和'.chkbox2'
是一样的。这部分,取值对吗?
$('#productId').val(msg[0].productId); if ('.chkbox2'.val() == true){
$('.chkbox2').check(checked);
};
最佳答案
$('.chkbox2').prop('checked', true);
用这个来勾选复选框
关于php - 如果其值在数据库中,请选中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25259716/