多个checkbox 回显

1,使用javascript 方法
添加一个隐藏域,而后分割遍历
var strRoles = $("#userRoles").val();
if (strRoles.length>0) {
    var roleArr = strRoles.split(',');
    $.each(roleArr, function(index, roleName){
        $("input[type=checkbox][name='roles[]']").each(function () {
            if($(this).val() == roleName) {
                $(this).attr("checked",true);
            }
        });
    });
}

能够参考一下:http://www.tuicool.com/articles/bMV7j2ujavascript

相关文章
相关标签/搜索