双表的增删改查-add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加页面</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/index2.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<form id="fid">
<div class="container">
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">姓名<input type="text" name="name" > </th>
</tr>
<tr>
<th scope="col">身份证编号<input type="text" name="sfz" > </th>
</tr>
<tr>
<th scope="col">电话<input type="text" name="telephone" > </th>
</tr>
<tr>
<th scope="col">性别<input type="radio" name="grader" value="1" >男<input type="radio" name="grader" value="2" >女 </th>
</tr>
<tr>
<th scope="col">省:<select name="province" onchange="shen()" id="ss">
<c:forEach items="${province}" var="d">
<option value="${d.id}">${d.sname}</option>
</c:forEach>
</select></th>
</tr>
<tr>
<th scope="col">市<select name="town" onchange="shi()" id="town">
</select> </th>
</tr>
<tr>
<th scope="col">县<select name="county" onchange="xian()" id="county">
</select> </th>
</tr>
<tr>
<th scope="col">科室<select name="desk">
<c:forEach items="${listDepart}" var="d">
<option value="${d.id}">${d.kname}</option>
</c:forEach>

</select> </th>
</tr>
<tr>
<th scope="col">擅长
<c:forEach items="${shanchang}" var="s" >
<input type="checkbox" name="scname" value="${s.id}" >${s.sname}
</c:forEach>
</th>
</tr>
<tr>
<th scope="col">入职日期<input type="date" name="rzdate" ></th>
</tr>
<tr>
<th scope="col">出生日期<input type="date" name="birthday" ></th>
</tr>
<tr>
<th scope="col">
<input type="file" name="file" value="${d.touxiang}" >
</th>
</tr>
<tr>
<td>
<button type="button" class="btn btn-primary" onclick="xg()" >保存</button>
</td>
</tr>
</thead>
</table>
</div>
</form>

<script type="text/javascript">
function xg(){
var formData = new FormData($("#fid")[0]);
$.ajax({
url:'/add',
type:'post',
processData:false,
data:formData,
contentType:false,
success:function(obj){
if(obj>0){
alert("添加成功");
location.href="/list";
}else{
alert("添加失败");
location.href="/update";
}
}
})
}
function shen() {
var id = $("#ss").val();
$.ajax({
url:'/city',
data:{id:id},
type:'post',
dataType:'JSON',
success:function(obj){
$("#county").empty();
$("#town").empty();
for ( var i in obj) {
$("#town").append("<option value="+obj[i].id+" >"+obj[i].sname+"</option>")
}
}
})
}
function shi() {
var id = $("#town").val();
$.ajax({
url:'/city',
data:{id:id},
type:'post',
dataType:'JSON',
success:function(obj){
$("#county").empty();
for ( var i in obj) {
$("#county").append("<option value="+obj[i].id+" >"+obj[i].sname+"</option>")
}
}
})
}
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/liuzhaolong/p/12874588.html