使用jquery动态添加学生信息
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.navBar {
border: 1px solid rgba(0,0,0,0.1);
width: 1000px;
height: 60px;
line-height: 60px;
text-align: center;
position: absolute;
left: 50%;
margin-left: -500px;
}
.navBar input {
outline-style: none;
}
.navTable table {
width: 1000px;
border: 1px solid #000000;
border-collapse: collapse;
position: fixed;
left: 50%;
top: 15%;
margin-left: -500px;
}
.navTable tr {
border: 1px solid #000000;
}
.navTable th {
background-color: skyblue;
border: 1px solid #000000;
height: 34px;
line-height: 34px;
}
.navTable td {
border: 1px solid #000000;
text-align: center;
height: 26px;
line-height: 26px;
position: relative;
}
.navTable td a {
position: absolute;
width: 60px;
height: 22px;
line-height: 22px;
left: 50%;
top: 50%;
margin-top: -12px;
margin-left: -30px;
text-align: center;
color: black;
text-decoration: none;
border: 1px solid #000000;
background-color: #f5f5f5;
border-radius: 3px;
}
.navTable td a:hover {
color: blue;
}
</style>
</head>
<body>
<script src="../jQuery/jquery/jquery.js"></script>
<script>
$( () => {
$(document).attr("title", "动态添加学生信息");
$('#btn').click( () => {
const sOrder = $('#sOrder').val();
const sName = $('#sName').val();
const sId = $('#sId').val();
const sSex = $("input[type='radio']:checked").val();
const tr = $("<tr>" +
"<td> " + sOrder + "</td>" +
"<td> " + sName + "</td>" +
"<td> " + sId + " </td>" +
"<td> " + sSex + " </td>" +
"<td><a href='deleteEmp?id="+ sOrder + "'>删除</a></td>" +
"</tr>");
$(".navTable table").append(tr);
tr.children().children().click( () => {
tr.remove();
return false;
})
})
})
</script>
<div class="navBar">
序号:<input type="text" value="" id="sOrder" placeholder="请输入你的序号...">
姓名:<input type="text" value="" id="sName" placeholder="请输入你的姓名...">
学号:<input type="text" value="" id="sId" placeholder="请输入你的学号...">
<span>性别:</span>
男:<input type="radio" name="sex" checked="checked" class="sSex sSexFirst" value="男">
女:<input type="radio" name="sex" class="sSex sSexSecond" value="女">
<input type="button" value="添加" id="btn">
</div>
<div class="navTable">
<table>
<tr>
<th>序号</th>
<th>姓名</th>
<th>学号</th>
<th>性别</th>
<th>操作</th>
</tr>
</table>
</div>
</body>
</html>