如果数据库中的数据是或否,如何使复选框处于选中状态,我尝试使用attr函数,但该方法不起作用
_ts
这是我的html
if(data[1].grace == 'yes'){
console.log('this is yes');
$("#grace").attr("checked",true);
}else{
console.log('this is no');
}
答案 0 :(得分:-1)
尝试触发该复选框
$("#grace").trigger('click');
答案 1 :(得分:-1)
您是否正确导入了jQuery?控制台有任何错误吗?
https://codepen.io/fuleinist/pen/PowqgRY这对我有用。
$(document).ready(function() {
$("#grace").attr("checked",true);
});