layui checkbox多选框自动选中

layui 的checkbox,后台返回数据,前台自动选中问题

$.get(
       "{:url('service/edit')}",
       {'id':adminId},
       function(d){  //d为后台返回的json数据
            //设置品种 多选框
            arr = d.quotation_type.split(','); //存的时候是多个值拼成的字符串,这里劈成数组
            for(i=0;i<arr.length;i++){
                var quotationCheckbox = $("input[name=quotation_type]");  //有所的checkbox
                for(j=0;j<quotationCheckbox.length;j++){
                    if(quotationCheckbox[j].value == arr[i]){
                        quotationCheckbox[i].checked=true;  //设置选中
                     }
                }
            }

            form.render(); //更新全部
          }
);

马克一下

猜你喜欢

转载自blog.csdn.net/Gino_tkzzz/article/details/84324818