先做草稿,稍后完善,
javascript
for (var i = 0; i < jsonmsg.length; i++) {
var ischecked = false;
for (var j = 0; j < jsonarg1.length; j++) {
console.info(jsonarg1[j]["Tag_ID"] + "----" + jsonmsg[i]["TabId"]);
if (jsonarg1[j]["Tag_ID"] === jsonmsg[i]["TabId"]) {
ischecked = true;
}
}
$("#ModalList").append("<input type='checkbox' name='TagName' " + (ischecked === true ? "checked='checked'" : "") + " value='" + jsonmsg[i]["TabId"] + "' />" + jsonmsg[i]["Names"]);
}
asp.net
@{
foreach (IAMS.DATASERVICE.JiaoBao.SSchedule.Model.Schedule_Tag t in taginfolist)
{
var ischecked = false;
foreach (IAMS.DATASERVICE.JiaoBao.SSchedule.Model.Schedule_Tag_Info ti in tagidlist)
{
if (t.TabId == ti.Tag_ID)
{
ischecked = true; } } <input type="checkbox" name="TagIDs" value="@t.TabId" checked="@ischecked" /> @t.Names
}
}
checkbox 中的 checked 属性 Js 控制 无论等于true 或者false 都会是被选中状态