一、另写一个delete.html文件,
二、删除操作点击后进入delete.html
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>删除信息</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="lib/getParameter.js"></script>
</head>
<body>
<script type="text/javascript">
// 函数:根据传递过来的参数name获取对应的值
function getParameter(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
var r = location.search.substr(1).match(reg);
if (r!=null) return (r[2]); return null;
}
$(function () {
var id = getParameter("id");
$.ajax({
url:"/delete",
type:"post",
dataType:"json",
data:{id:id},
success:function () {
//这里是让页面重新回到表格页面index.html
window.location.href="index.html";
}
});
});
</script>
</body>
</html>
//此代码在回调函数内
//表格页面中删除操作代码
//此a标签可以放入button标签内,并设置单击事件
//data是要传入delete.html界面的数据
<a href='delete.html?id="+data+"'>删除</a>