复选框 回显

//查询到的地质地貌
var old_landform = data[i].landform;
//console.log(old_landform)
//获取原来选中的值并拆分
var checkArray = old_landform.split("、");
// console.log(checkArray)
//获取所有复选框的值
var checkBoxAll = $("input[name='hobby']");
for (var la = 0; la < checkArray.length; la++) {
//获取所有复选框对象的value属性,然后,用checkArray[i]和他们匹配,如果有,则说明他应被选中
$.each(checkBoxAll, function (xx, checkbox) {
//获取复选框的value属性
var checkValue = $(checkbox).val();
if (checkArray[la] == checkValue) {
// console.log(8888888)
$(checkbox).attr("checked", true);
}
})
}
原文地址:https://www.cnblogs.com/heyiming/p/11477860.html