使用jquery在html中加载页面后动态检查复选框


Dynamically check checkbox after loading the page in html using jquery

我正在编写一个包含复选框的页面。用户检查其中的一些,它们的值存储在某个表中。现在,如果用户再次访问该页面,则读取先前存储的表值。现在我想选中那些值被存储的框,其余的框保持未选中状态。有人能帮帮我吗?

$(document).ready(function () {
    //Read table
    //Check appropriate checkboxed
    $('#cb2').attr('checked', 'checked');
});

使用.prop().attr()非常容易

$('.some-selector-for-radio-or-checkbox').prop('checked', true);
$(document).ready(function () {
    //Read table
    //Check appropriate checkboxed
    $('#Your CheckBox ID ').attr('checked', 'checked');
});