修改省、删除省
16lz
2021-07-31
修改省、删除省
作业标题:0723作业
作业内容:大作业 1、修改省 - 获取省份:http://admin.ouyangke.cn/index.php/api/index/prov_one - 修改接口:http://admin.ouyangke.cn/index.php/api/index/prov_edit 2、删除省 - 删除接口:http://admin.ouyangke.cn/index.php/api/index/prov_del
删除
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<style>
* {
text-align: center;
font-size: 20px;
}
.title {
text-align: center;
}
.width {
width: 1200px;
}
tr {
height: 50px;
}
</style>
</head>
<body>
<h2 class="title">省份表</h2>
<div style="margin: 20px 200px; text-align: right">
<button id="add">添加</button>
</div>
<table class="width" id="tableId" border="1" align="center" cellspacing="0">
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>首字母</th>
<th>拼音</th>
<th>精度</th>
<th>维度</th>
<th colspan="2">编辑</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div style="margin-top: 20px">
<button id="lower">更多</button>
</div>
</body>
<script>
// $.ajax() ajax的异步http 请求
// $.get() 和 $.post() 方法都使用 $.ajax
// function get(url,data,fun,type){
// url 处理
// data 处理
// fun 处理
// type 处理
// $.ajax(url,data,fun,type)
// }
// 因为get 和post方法,可以快速去执行,方便我们写代码
// $.ajax({
// key : value,
// key : value,
// key : value,
// key : value,
// key : value,
// key : value
// })
// key 就是参数
// url 必需、请求的接口
// data 给接口的数据、参数
// type get、post
// async 是否要异步处理,布尔值,true异步,false同步
// dataType 服务器的数据类型
// timeout 超时时间 ,毫秒。 2000,如果2秒,这个接口没有反应,这个请求就停止
// success(data,status) 请求成功的方法
// error(data,status) 请求失败的方法
// complete(data,status) 不管成功还是失败,都会执行
var js_page = 1;
data(js_page);
$("#lower").click(function () {
js_page = js_page + 1;
data(js_page);
});
function data(js_page) {
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_list",
data: {
page: js_page,
limit: 10,
//order: desc,
},
type: "GET",
async: false,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data, status) {
let html_data = "";
for (let i = 0; i < data.data.length; i++) {
html_data += "<tr>";
html_data += "<th>" + data.data[i].area_id + "</th>";
html_data += "<td>" + data.data[i].area_name + "</td>";
html_data += "<td>" + data.data[i].pinyin + "</td>";
html_data += "<td>" + data.data[i].first_pinyin + "</td>";
html_data += "<td>" + data.data[i].lng + "</td>";
html_data += "<td>" + data.data[i].lat + "</td>";
html_data +=
"<td>" +
"<button id=" +
data.data[i].area_id +
">" +
"删除" +
"</button>" +
"</td>";
html_data +=
"<td>" +
"<button class=" +
data.data[i].area_id +
">" +
"修改" +
"</button>" +
"</td>";
html_data += "</tr>";
}
$("tbody").append(html_data);
count = Math.ceil(data.count / 10);
console.log("天蓬");
},
// complete(data) {
// console.log(data);
// },
});
}
// 异步处理:ajax这段代码,放那执行,其他代码不会受它的影响,会直接继续指向。
// 你跟你爸妈 ,周天出去玩。。 到了周天,你说有事了。
// 这个时候,有2个选择:
// 1、你爸妈 它俩去。 异步处理
// 2、你爸妈 等你处理完事(下周),在去。 同步处理
// 如果是同步处理,打印欧阳克这段代码,必须等 上面的ajax执行完了, 才会执行。
// 现在是没有等ajax执行完,它就执行了,这是 异步处理。
console.log("欧阳克");
// 改为同步处理,async:false, 就是天蓬先打印出来,欧阳克要等ajax执行完,才会被打印出来
// $.ajax 是jquery底层ajax,底层封装一个方法
// get、 post 是对ajax 进一步封装
$("#add").click(function () {
window.location.href = "7.html";
});
//删除按钮
let del_id;
$(document).click(function (e) {
// 在页面任意位置点击而触发此事件
del_id = $(e.target).attr("id"); // e.target表示被点击的目标
console.log(del_id);
if (del_id > 820307) {
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_del",
data: {
area_id: del_id,
},
type: "POST",
async: false,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data) {
if (data.code == 0) {
alert("success");
window.location.href = "6.html";
} else {
alert("添加失败,请重试");
return false;
}
},
// complete(data) {
// console.log(data);
// },
});
}
});
//编辑按钮
let index_name;
//button[(name = "area_name")];
$(document).click(function (e) {
// 在页面任意位置点击而触发此事件
index_name = e.target.className * 1; // e.target表示被点击的目标
console.log(index_name);
if (index_name > 820307) {
alert(index_name);
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_one",
data: {
area_id: index_name,
},
type: "POST",
async: true,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data) {
if (data.code == 0) {
alert("success");
window.location.href = "8.html?area_id=" + index_name;
} else {
alert("添加失败,请重试");
return false;
}
},
complete(data) {
console.log(data);
},
});
}
});
</script>
</html>
编辑(点击编辑跳转)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<style>
* {
text-align: center;
font-size: 20px;
}
.title {
text-align: center;
}
.width {
width: 1200px;
}
tr {
height: 50px;
}
</style>
</head>
<body>
<h2 class="title">省份表</h2>
<div style="margin: 20px 200px; text-align: right">
<button id="add">添加</button>
</div>
<table class="width" id="tableId" border="1" align="center" cellspacing="0">
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>首字母</th>
<th>拼音</th>
<th>精度</th>
<th>维度</th>
<th colspan="2">编辑</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div style="margin-top: 20px">
<button id="lower">更多</button>
</div>
</body>
<script>
// $.ajax() ajax的异步http 请求
// $.get() 和 $.post() 方法都使用 $.ajax
// function get(url,data,fun,type){
// url 处理
// data 处理
// fun 处理
// type 处理
// $.ajax(url,data,fun,type)
// }
// 因为get 和post方法,可以快速去执行,方便我们写代码
// $.ajax({
// key : value,
// key : value,
// key : value,
// key : value,
// key : value,
// key : value
// })
// key 就是参数
// url 必需、请求的接口
// data 给接口的数据、参数
// type get、post
// async 是否要异步处理,布尔值,true异步,false同步
// dataType 服务器的数据类型
// timeout 超时时间 ,毫秒。 2000,如果2秒,这个接口没有反应,这个请求就停止
// success(data,status) 请求成功的方法
// error(data,status) 请求失败的方法
// complete(data,status) 不管成功还是失败,都会执行
var js_page = 1;
data(js_page);
$("#lower").click(function () {
js_page = js_page + 1;
data(js_page);
});
function data(js_page) {
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_list",
data: {
page: js_page,
limit: 10,
//order: desc,
},
type: "GET",
async: false,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data, status) {
let html_data = "";
for (let i = 0; i < data.data.length; i++) {
html_data += "<tr>";
html_data += "<th>" + data.data[i].area_id + "</th>";
html_data += "<td>" + data.data[i].area_name + "</td>";
html_data += "<td>" + data.data[i].pinyin + "</td>";
html_data += "<td>" + data.data[i].first_pinyin + "</td>";
html_data += "<td>" + data.data[i].lng + "</td>";
html_data += "<td>" + data.data[i].lat + "</td>";
html_data +=
"<td>" +
"<button id=" +
data.data[i].area_id +
">" +
"删除" +
"</button>" +
"</td>";
html_data +=
"<td>" +
"<button class=" +
data.data[i].area_id +
">" +
"修改" +
"</button>" +
"</td>";
html_data += "</tr>";
}
$("tbody").append(html_data);
count = Math.ceil(data.count / 10);
console.log("天蓬");
},
// complete(data) {
// console.log(data);
// },
});
}
// 异步处理:ajax这段代码,放那执行,其他代码不会受它的影响,会直接继续指向。
// 你跟你爸妈 ,周天出去玩。。 到了周天,你说有事了。
// 这个时候,有2个选择:
// 1、你爸妈 它俩去。 异步处理
// 2、你爸妈 等你处理完事(下周),在去。 同步处理
// 如果是同步处理,打印欧阳克这段代码,必须等 上面的ajax执行完了, 才会执行。
// 现在是没有等ajax执行完,它就执行了,这是 异步处理。
console.log("欧阳克");
// 改为同步处理,async:false, 就是天蓬先打印出来,欧阳克要等ajax执行完,才会被打印出来
// $.ajax 是jquery底层ajax,底层封装一个方法
// get、 post 是对ajax 进一步封装
$("#add").click(function () {
window.location.href = "7.html";
});
//删除按钮
let del_id;
$(document).click(function (e) {
// 在页面任意位置点击而触发此事件
del_id = $(e.target).attr("id"); // e.target表示被点击的目标
console.log(del_id);
if (del_id > 820307) {
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_del",
data: {
area_id: del_id,
},
type: "POST",
async: false,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data) {
if (data.code == 0) {
alert("success");
window.location.href = "6.html";
} else {
alert("添加失败,请重试");
return false;
}
},
// complete(data) {
// console.log(data);
// },
});
}
});
//编辑按钮
let index_name;
//button[(name = "area_name")];
$(document).click(function (e) {
// 在页面任意位置点击而触发此事件
index_name = e.target.className * 1; // e.target表示被点击的目标
console.log(index_name);
if (index_name > 820307) {
alert(index_name);
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_one",
data: {
area_id: index_name,
},
type: "POST",
async: true,
dataType: "json",
timeout: 10000,
// success :function(){
// },
success(data) {
if (data.code == 0) {
alert("success");
window.location.href = "8.html?area_id=" + index_name;
} else {
alert("添加失败,请重试");
return false;
}
},
complete(data) {
console.log(data);
},
});
}
});
</script>
</html>
编辑(修改页面)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<style>
* {
background-color: #d4edda;
text-align: center;
font-size: 20px;
}
.form-control {
width: 500px;
padding: 0.375rem 0.75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
button {
width: 600px;
color: #fff;
background-color: #28a745;
border-color: #28a745;
}
.select {
width: 265px;
height: 47px;
}
</style>
<h2 class="title">修改省</h2>
<form action="" onsubmit="return false;">
<p>
省名称:
<input type="text" class="form-control" id="area_name" />
</p>
<p>
首字母:
<input type="text" class="form-control" id="pinyin" />
</p>
<p>
拼音:
<input type="text" class="form-control" id="first_pinyin" />
</p>
<p>
精度:
<input type="text" class="form-control" id="lng" />
</p>
<p>
维度:
<input type="text" class="form-control" id="lat" />
</p>
<button>按钮</button>
<div id="msg" style="margin-top: 20px; color: Red; display: none"></div>
</form>
</body>
<script>
$("#area_name").keydown(function () {
$("#msg").hide();
});
$("#pinyin").keydown(function () {
$("#msg").hide();
});
$("#first_pinyin").keydown(function () {
$("#msg").hide();
});
$("#lng").keydown(function () {
$("#msg").hide();
});
$("#lat").keydown(function () {
$("#msg").hide();
});
$("button").click(function () {
let area_name = $("#area_name").val();
if (!area_name) {
msg("请输入省的名称");
return false;
}
let pinyin = $("#pinyin").val();
if (!pinyin) {
msg("请输入首字母");
return false;
}
let first_pinyin = $("#first_pinyin").val();
if (!first_pinyin) {
msg("请输入省份的拼音");
return false;
}
let lng = $("#lng").val();
if (!lng) {
msg("请输入精度");
return false;
}
let lat = $("#lat").val();
if (!lat) {
msg("请输入维度");
return false;
}
// 增加省接口:http://admin.ouyangke.cn/index.php/api/index/prov_add
//获取数据
// $.ajax({
// url: "http://admin.ouyangke.cn/index.php/api/index/prov_one?area_id",
// type: "POST",
// async: true,
// dataType: "json",
// // success :function(){
// // },
// success(data) {
// if (data.code == 0) {
// alert("success");
// } else {
// alert("添加失败,请重试111111");
// return false;
// }
// },
// complete(data) {
// console.log(data);
// },phone.slice(-6)
// });
let area_id = window.location.search;
area_id = area_id.slice(-6);
alert(area_id);
//修改数据
$.ajax({
url: "http://admin.ouyangke.cn/index.php/api/index/prov_edit",
type: "POST",
data: {
area_id: area_id,
area_name: area_name, // 第一个area_name接口的参数(下标)
pinyin: pinyin,
first_pinyin: first_pinyin,
lng: lng,
lat: lat,
},
dataType: "json",
success(data) {
console.log(data);
if (data.code == 0) {
window.location.href = "6.html";
} else {
msg("修改失败,请重试");
return false;
}
},
});
});
function msg(text) {
$("#msg").text(text);
$("#msg").show();
}
</script>
</html>
更多相关文章
- 匿名函数、箭头函数、立即执行函数和字面量
- 匿名函数、箭头函数和立即执行函数
- axios的跨域处理
- JS 函数的执行时机
- 16.【TP6学习笔记】其他通过CMD命令行的方式执行操作
- PHP:文件上传上传限制,文件大小不超过5M,文件后缀设置,检查图片合
- 详解支撑7亿用户搜索的百度图片处理收录中台
- 实现一个简易数字货币现货跟单机器人
- 自然语言处理集训营第一期