JQuery 修改用户信息,多项选择,赋值,框架: https://www.h-ui.net/v3.shtml
$(data.data.roleList).each(function (i, val) {
$('input[type="checkbox"][name="doctorRole"]').each(function () {
if (this.value == val.roleCode) {
this.checked = true;
}
});
})
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加医生</title>
</head>
<body>
<article class="page-container">
<form class="form form-horizontal" id="form-doctor-add">
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>工号:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text" value="" placeholder="" id="doctorNo" name="doctorNo">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text" value="" placeholder="" id="doctorName" name="doctorName">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3">性别:</label>
<div class="formControls col-xs-8 col-sm-9 skin-minimal">
<div class="radio-box">
<input type="radio" name="sex" value="1" id="sex-1" checked>
<label for="sex-1">男</label>
</div>
<div class="radio-box">
<input type="radio" name="sex" value="2" id="sex-2">
<label for="sex-2">女</label>
</div>
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3">手机:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text" value="" placeholder="" id="phone" name="phone">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3">角色:</label>
<div class="formControls col-xs-8 col-sm-9">
<div class="check-box">
<input type="checkbox" id="chkAnalysis" name="doctorRole" value="analysis">
<label for="chkAnalysis">分析员</label>
</div>
<div class="check-box">
<input type="checkbox" id="chkAudit" name="doctorRole" value="audit">
<label for="chkAudit">审核员</label>
</div>
<div class="check-box">
<input type="checkbox" id="chkReview" name="doctorRole" value="review">
<label for="chkReview">复核员</label>
</div>
</div>
</div>
<div class="row cl">
<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
<input class="btn btn-primary radius" type="submit" value=" 提交 ">
<input type="hidden" id="hidId" value=""/>
</div>
</div>
</form>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="style/js/config.js"></script>
<script type="text/javascript" src="style/js/common.js"></script>
<!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function () {
if ($.cookie('LoginUser') === undefined) {
top.location = 'login.html';
}
var queryString = window.location.search;
var params = {};
if (queryString) {
var pairs = queryString.split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
if(pair.length>0){
params[pair[0].replace('?','')] = pair[1];
}
}
}
if (params.doctorNo != null) {
getDoctorInfo(params);
}
function getDoctorInfo(params) {
var mask;
$.ajax({
url: GLOBAL_CONFIG.HOST + "/admin/getUser",
type: 'post',
dataType: 'json',
contentType: "application/json;charset=utf-8",
headers: {
'SecretKey': GLOBAL_APPCONFIG.AppId
},
data: JSON.stringify(params),
beforeSend: function (XMLHttpRequest) {
mask = layer.msg("数据获取中....", {icon: 16, time: 60000, shade: 0.1});
},
success: function (data) {
$("#hidId").val(data.data.id);
$("#doctorNo").val(data.data.doctorNo);
$("#doctorName").val(data.data.doctorName);
$("#phone").val(data.data.phoneNo);
if (data.data.sex == 1) {
$("#sex-1").attr("checked", true);
}
else {
$("#sex-2").attr("checked", true);
}
$(data.data.roleList).each(function (i, val) {
$('input[type="checkbox"][name="doctorRole"]').each(function () {
if (this.value == val.roleCode) {
this.checked = true;
}
});
})
layer.close(mask);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
layer.msg('error!', {icon: 1, time: 1000});
}
});
}
$('.skin-minimal input').iCheck({
checkboxClass: 'icheckbox-blue',
radioClass: 'iradio-blue',
increaseArea: '20%'
});
$("#form-doctor-add").validate({
rules: {
doctorNo: {
required: true,
minlength: 3,
maxlength: 16
},
doctorName: {
required: true,
minlength: 2,
maxlength: 16
},
doctorRole: {
required: true,
},
phone: {
isPhone: true,
},
},
onkeyup: false,
focusCleanup: true,
success: "valid",
submitHandler: function (form) {
var userRoleList = new Array();
$('input[type="checkbox"][name="doctorRole"]').each(function () {
if (this.checked) {
var userRole = {}
var val = $(this).val();
userRole.roleCode = val;
userRoleList.push(userRole);
}
});
var obj = {};
obj.id = $("#hidId").val().trim();
obj.doctorNo = $("#doctorNo").val().trim();
obj.doctorName = $("#doctorName").val().trim();
obj.sex = $("input[name='sex']:checked").val();
obj.phoneNo = $("#phone").val().trim();
obj.roleList = userRoleList;
//$(form).ajaxSubmit({
$.ajax({
url: GLOBAL_CONFIG.HOST + "/admin/addDoctor",
type: 'post',
dataType: 'json',
contentType: "application/json;charset=utf-8",
headers: {
'SecretKey': GLOBAL_APPCONFIG.AppId
},
data: JSON.stringify(obj),
beforeSend: function (XMLHttpRequest) {
layer.msg("数据提交中....", {icon: 16, time: 60000, shade: 0.1});
},
success: function (data) {
console.log(data)
layer.msg('添加成功!', {icon: 1, time: 1000});
var index = parent.layer.getFrameIndex(window.name);
parent.$('.btn-refresh').click();
parent.layer.close(index);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
layer.msg('error!', {icon: 1, time: 1000});
}
});
}
});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
{
"id": "25465bcb-a9b4-4785-9caf-8ca9561fd61e",
"doctorNo": "123",
"pwd": "b095c7cfa04f19a9c8bce5f2590a035c",
"doctorName": "456",
"sex": 2,
"phoneNo": "13666666",
"deptName": null,
"jobTitle": null,
"isSuperAdmin": 0,
"remark": null,
"createTime": "2023-12-25T07:36:05.000+00:00",
"updateTime": null,
"isDeleted": 0,
"status": 1,
"roleList": [
{
"id": "a9994936-c06d-4ed5-ae72-0cfa91270a59",
"doctorNo": "123",
"roleId": null,
"roleCode": "analysis",
"roleName": "分析员",
"remark": null,
"createTime": "2023-12-25T07:37:06.000+00:00",
"updateTime": null,
"isDeleted": 0,
"status": 1
},
{
"id": "ea33f4bd-08ae-4eb5-b497-f18c1fa8c802",
"doctorNo": "123",
"roleId": null,
"roleCode": "review",
"roleName": "复核员",
"remark": null,
"createTime": "2023-12-25T07:37:06.000+00:00",
"updateTime": null,
"isDeleted": 0,
"status": 1
}
],
"newPwd": null
}
标签:JQuery,function,val,true,用户,修改,var,null,data
From: https://www.cnblogs.com/vipsoft/p/17933339.html