修改省、删除省

作业标题: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

  • 删除

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8" />
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    7. <title>Document</title>
    8. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    9. <style>
    10. * {
    11. text-align: center;
    12. font-size: 20px;
    13. }
    14. .title {
    15. text-align: center;
    16. }
    17. .width {
    18. width: 1200px;
    19. }
    20. tr {
    21. height: 50px;
    22. }
    23. </style>
    24. </head>
    25. <body>
    26. <h2 class="title">省份表</h2>
    27. <div style="margin: 20px 200px; text-align: right">
    28. <button id="add">添加</button>
    29. </div>
    30. <table class="width" id="tableId" border="1" align="center" cellspacing="0">
    31. <thead>
    32. <tr>
    33. <th>编号</th>
    34. <th>名称</th>
    35. <th>首字母</th>
    36. <th>拼音</th>
    37. <th>精度</th>
    38. <th>维度</th>
    39. <th colspan="2">编辑</th>
    40. </tr>
    41. </thead>
    42. <tbody></tbody>
    43. </table>
    44. <div style="margin-top: 20px">
    45. <button id="lower">更多</button>
    46. </div>
    47. </body>
    48. <script>
    49. // $.ajax() ajax的异步http 请求
    50. // $.get() 和 $.post() 方法都使用 $.ajax
    51. // function get(url,data,fun,type){
    52. // url 处理
    53. // data 处理
    54. // fun 处理
    55. // type 处理
    56. // $.ajax(url,data,fun,type)
    57. // }
    58. // 因为get 和post方法,可以快速去执行,方便我们写代码
    59. // $.ajax({
    60. // key : value,
    61. // key : value,
    62. // key : value,
    63. // key : value,
    64. // key : value,
    65. // key : value
    66. // })
    67. // key 就是参数
    68. // url 必需、请求的接口
    69. // data 给接口的数据、参数
    70. // type get、post
    71. // async 是否要异步处理,布尔值,true异步,false同步
    72. // dataType 服务器的数据类型
    73. // timeout 超时时间 ,毫秒。 2000,如果2秒,这个接口没有反应,这个请求就停止
    74. // success(data,status) 请求成功的方法
    75. // error(data,status) 请求失败的方法
    76. // complete(data,status) 不管成功还是失败,都会执行
    77. var js_page = 1;
    78. data(js_page);
    79. $("#lower").click(function () {
    80. js_page = js_page + 1;
    81. data(js_page);
    82. });
    83. function data(js_page) {
    84. $.ajax({
    85. url: "http://admin.ouyangke.cn/index.php/api/index/prov_list",
    86. data: {
    87. page: js_page,
    88. limit: 10,
    89. //order: desc,
    90. },
    91. type: "GET",
    92. async: false,
    93. dataType: "json",
    94. timeout: 10000,
    95. // success :function(){
    96. // },
    97. success(data, status) {
    98. let html_data = "";
    99. for (let i = 0; i < data.data.length; i++) {
    100. html_data += "<tr>";
    101. html_data += "<th>" + data.data[i].area_id + "</th>";
    102. html_data += "<td>" + data.data[i].area_name + "</td>";
    103. html_data += "<td>" + data.data[i].pinyin + "</td>";
    104. html_data += "<td>" + data.data[i].first_pinyin + "</td>";
    105. html_data += "<td>" + data.data[i].lng + "</td>";
    106. html_data += "<td>" + data.data[i].lat + "</td>";
    107. html_data +=
    108. "<td>" +
    109. "<button id=" +
    110. data.data[i].area_id +
    111. ">" +
    112. "删除" +
    113. "</button>" +
    114. "</td>";
    115. html_data +=
    116. "<td>" +
    117. "<button class=" +
    118. data.data[i].area_id +
    119. ">" +
    120. "修改" +
    121. "</button>" +
    122. "</td>";
    123. html_data += "</tr>";
    124. }
    125. $("tbody").append(html_data);
    126. count = Math.ceil(data.count / 10);
    127. console.log("天蓬");
    128. },
    129. // complete(data) {
    130. // console.log(data);
    131. // },
    132. });
    133. }
    134. // 异步处理:ajax这段代码,放那执行,其他代码不会受它的影响,会直接继续指向。
    135. // 你跟你爸妈 ,周天出去玩。。 到了周天,你说有事了。
    136. // 这个时候,有2个选择:
    137. // 1、你爸妈 它俩去。 异步处理
    138. // 2、你爸妈 等你处理完事(下周),在去。 同步处理
    139. // 如果是同步处理,打印欧阳克这段代码,必须等 上面的ajax执行完了, 才会执行。
    140. // 现在是没有等ajax执行完,它就执行了,这是 异步处理。
    141. console.log("欧阳克");
    142. // 改为同步处理,async:false, 就是天蓬先打印出来,欧阳克要等ajax执行完,才会被打印出来
    143. // $.ajax 是jquery底层ajax,底层封装一个方法
    144. // get、 post 是对ajax 进一步封装
    145. $("#add").click(function () {
    146. window.location.href = "7.html";
    147. });
    148. //删除按钮
    149. let del_id;
    150. $(document).click(function (e) {
    151. // 在页面任意位置点击而触发此事件
    152. del_id = $(e.target).attr("id"); // e.target表示被点击的目标
    153. console.log(del_id);
    154. if (del_id > 820307) {
    155. $.ajax({
    156. url: "http://admin.ouyangke.cn/index.php/api/index/prov_del",
    157. data: {
    158. area_id: del_id,
    159. },
    160. type: "POST",
    161. async: false,
    162. dataType: "json",
    163. timeout: 10000,
    164. // success :function(){
    165. // },
    166. success(data) {
    167. if (data.code == 0) {
    168. alert("success");
    169. window.location.href = "6.html";
    170. } else {
    171. alert("添加失败,请重试");
    172. return false;
    173. }
    174. },
    175. // complete(data) {
    176. // console.log(data);
    177. // },
    178. });
    179. }
    180. });
    181. //编辑按钮
    182. let index_name;
    183. //button[(name = "area_name")];
    184. $(document).click(function (e) {
    185. // 在页面任意位置点击而触发此事件
    186. index_name = e.target.className * 1; // e.target表示被点击的目标
    187. console.log(index_name);
    188. if (index_name > 820307) {
    189. alert(index_name);
    190. $.ajax({
    191. url: "http://admin.ouyangke.cn/index.php/api/index/prov_one",
    192. data: {
    193. area_id: index_name,
    194. },
    195. type: "POST",
    196. async: true,
    197. dataType: "json",
    198. timeout: 10000,
    199. // success :function(){
    200. // },
    201. success(data) {
    202. if (data.code == 0) {
    203. alert("success");
    204. window.location.href = "8.html?area_id=" + index_name;
    205. } else {
    206. alert("添加失败,请重试");
    207. return false;
    208. }
    209. },
    210. complete(data) {
    211. console.log(data);
    212. },
    213. });
    214. }
    215. });
    216. </script>
    217. </html>

    删除
    删除


  • 编辑(点击编辑跳转)

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8" />
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    7. <title>Document</title>
    8. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    9. <style>
    10. * {
    11. text-align: center;
    12. font-size: 20px;
    13. }
    14. .title {
    15. text-align: center;
    16. }
    17. .width {
    18. width: 1200px;
    19. }
    20. tr {
    21. height: 50px;
    22. }
    23. </style>
    24. </head>
    25. <body>
    26. <h2 class="title">省份表</h2>
    27. <div style="margin: 20px 200px; text-align: right">
    28. <button id="add">添加</button>
    29. </div>
    30. <table class="width" id="tableId" border="1" align="center" cellspacing="0">
    31. <thead>
    32. <tr>
    33. <th>编号</th>
    34. <th>名称</th>
    35. <th>首字母</th>
    36. <th>拼音</th>
    37. <th>精度</th>
    38. <th>维度</th>
    39. <th colspan="2">编辑</th>
    40. </tr>
    41. </thead>
    42. <tbody></tbody>
    43. </table>
    44. <div style="margin-top: 20px">
    45. <button id="lower">更多</button>
    46. </div>
    47. </body>
    48. <script>
    49. // $.ajax() ajax的异步http 请求
    50. // $.get() 和 $.post() 方法都使用 $.ajax
    51. // function get(url,data,fun,type){
    52. // url 处理
    53. // data 处理
    54. // fun 处理
    55. // type 处理
    56. // $.ajax(url,data,fun,type)
    57. // }
    58. // 因为get 和post方法,可以快速去执行,方便我们写代码
    59. // $.ajax({
    60. // key : value,
    61. // key : value,
    62. // key : value,
    63. // key : value,
    64. // key : value,
    65. // key : value
    66. // })
    67. // key 就是参数
    68. // url 必需、请求的接口
    69. // data 给接口的数据、参数
    70. // type get、post
    71. // async 是否要异步处理,布尔值,true异步,false同步
    72. // dataType 服务器的数据类型
    73. // timeout 超时时间 ,毫秒。 2000,如果2秒,这个接口没有反应,这个请求就停止
    74. // success(data,status) 请求成功的方法
    75. // error(data,status) 请求失败的方法
    76. // complete(data,status) 不管成功还是失败,都会执行
    77. var js_page = 1;
    78. data(js_page);
    79. $("#lower").click(function () {
    80. js_page = js_page + 1;
    81. data(js_page);
    82. });
    83. function data(js_page) {
    84. $.ajax({
    85. url: "http://admin.ouyangke.cn/index.php/api/index/prov_list",
    86. data: {
    87. page: js_page,
    88. limit: 10,
    89. //order: desc,
    90. },
    91. type: "GET",
    92. async: false,
    93. dataType: "json",
    94. timeout: 10000,
    95. // success :function(){
    96. // },
    97. success(data, status) {
    98. let html_data = "";
    99. for (let i = 0; i < data.data.length; i++) {
    100. html_data += "<tr>";
    101. html_data += "<th>" + data.data[i].area_id + "</th>";
    102. html_data += "<td>" + data.data[i].area_name + "</td>";
    103. html_data += "<td>" + data.data[i].pinyin + "</td>";
    104. html_data += "<td>" + data.data[i].first_pinyin + "</td>";
    105. html_data += "<td>" + data.data[i].lng + "</td>";
    106. html_data += "<td>" + data.data[i].lat + "</td>";
    107. html_data +=
    108. "<td>" +
    109. "<button id=" +
    110. data.data[i].area_id +
    111. ">" +
    112. "删除" +
    113. "</button>" +
    114. "</td>";
    115. html_data +=
    116. "<td>" +
    117. "<button class=" +
    118. data.data[i].area_id +
    119. ">" +
    120. "修改" +
    121. "</button>" +
    122. "</td>";
    123. html_data += "</tr>";
    124. }
    125. $("tbody").append(html_data);
    126. count = Math.ceil(data.count / 10);
    127. console.log("天蓬");
    128. },
    129. // complete(data) {
    130. // console.log(data);
    131. // },
    132. });
    133. }
    134. // 异步处理:ajax这段代码,放那执行,其他代码不会受它的影响,会直接继续指向。
    135. // 你跟你爸妈 ,周天出去玩。。 到了周天,你说有事了。
    136. // 这个时候,有2个选择:
    137. // 1、你爸妈 它俩去。 异步处理
    138. // 2、你爸妈 等你处理完事(下周),在去。 同步处理
    139. // 如果是同步处理,打印欧阳克这段代码,必须等 上面的ajax执行完了, 才会执行。
    140. // 现在是没有等ajax执行完,它就执行了,这是 异步处理。
    141. console.log("欧阳克");
    142. // 改为同步处理,async:false, 就是天蓬先打印出来,欧阳克要等ajax执行完,才会被打印出来
    143. // $.ajax 是jquery底层ajax,底层封装一个方法
    144. // get、 post 是对ajax 进一步封装
    145. $("#add").click(function () {
    146. window.location.href = "7.html";
    147. });
    148. //删除按钮
    149. let del_id;
    150. $(document).click(function (e) {
    151. // 在页面任意位置点击而触发此事件
    152. del_id = $(e.target).attr("id"); // e.target表示被点击的目标
    153. console.log(del_id);
    154. if (del_id > 820307) {
    155. $.ajax({
    156. url: "http://admin.ouyangke.cn/index.php/api/index/prov_del",
    157. data: {
    158. area_id: del_id,
    159. },
    160. type: "POST",
    161. async: false,
    162. dataType: "json",
    163. timeout: 10000,
    164. // success :function(){
    165. // },
    166. success(data) {
    167. if (data.code == 0) {
    168. alert("success");
    169. window.location.href = "6.html";
    170. } else {
    171. alert("添加失败,请重试");
    172. return false;
    173. }
    174. },
    175. // complete(data) {
    176. // console.log(data);
    177. // },
    178. });
    179. }
    180. });
    181. //编辑按钮
    182. let index_name;
    183. //button[(name = "area_name")];
    184. $(document).click(function (e) {
    185. // 在页面任意位置点击而触发此事件
    186. index_name = e.target.className * 1; // e.target表示被点击的目标
    187. console.log(index_name);
    188. if (index_name > 820307) {
    189. alert(index_name);
    190. $.ajax({
    191. url: "http://admin.ouyangke.cn/index.php/api/index/prov_one",
    192. data: {
    193. area_id: index_name,
    194. },
    195. type: "POST",
    196. async: true,
    197. dataType: "json",
    198. timeout: 10000,
    199. // success :function(){
    200. // },
    201. success(data) {
    202. if (data.code == 0) {
    203. alert("success");
    204. window.location.href = "8.html?area_id=" + index_name;
    205. } else {
    206. alert("添加失败,请重试");
    207. return false;
    208. }
    209. },
    210. complete(data) {
    211. console.log(data);
    212. },
    213. });
    214. }
    215. });
    216. </script>
    217. </html>
  • 编辑(修改页面)

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8" />
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    7. <title>Document</title>
    8. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    9. </head>
    10. <body>
    11. <style>
    12. * {
    13. background-color: #d4edda;
    14. text-align: center;
    15. font-size: 20px;
    16. }
    17. .form-control {
    18. width: 500px;
    19. padding: 0.375rem 0.75rem;
    20. font-size: 1rem;
    21. font-weight: 400;
    22. line-height: 1.5;
    23. color: #495057;
    24. background-color: #fff;
    25. background-clip: padding-box;
    26. border: 1px solid #ced4da;
    27. border-radius: 0.25rem;
    28. transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    29. }
    30. button {
    31. width: 600px;
    32. color: #fff;
    33. background-color: #28a745;
    34. border-color: #28a745;
    35. }
    36. .select {
    37. width: 265px;
    38. height: 47px;
    39. }
    40. </style>
    41. <h2 class="title">修改省</h2>
    42. <form action="" onsubmit="return false;">
    43. <p>
    44. 省名称:
    45. <input type="text" class="form-control" id="area_name" />
    46. </p>
    47. <p>
    48. 首字母:
    49. <input type="text" class="form-control" id="pinyin" />
    50. </p>
    51. <p>
    52. 拼音:
    53. <input type="text" class="form-control" id="first_pinyin" />
    54. </p>
    55. <p>
    56. 精度:
    57. <input type="text" class="form-control" id="lng" />
    58. </p>
    59. <p>
    60. 维度:
    61. <input type="text" class="form-control" id="lat" />
    62. </p>
    63. <button>按钮</button>
    64. <div id="msg" style="margin-top: 20px; color: Red; display: none"></div>
    65. </form>
    66. </body>
    67. <script>
    68. $("#area_name").keydown(function () {
    69. $("#msg").hide();
    70. });
    71. $("#pinyin").keydown(function () {
    72. $("#msg").hide();
    73. });
    74. $("#first_pinyin").keydown(function () {
    75. $("#msg").hide();
    76. });
    77. $("#lng").keydown(function () {
    78. $("#msg").hide();
    79. });
    80. $("#lat").keydown(function () {
    81. $("#msg").hide();
    82. });
    83. $("button").click(function () {
    84. let area_name = $("#area_name").val();
    85. if (!area_name) {
    86. msg("请输入省的名称");
    87. return false;
    88. }
    89. let pinyin = $("#pinyin").val();
    90. if (!pinyin) {
    91. msg("请输入首字母");
    92. return false;
    93. }
    94. let first_pinyin = $("#first_pinyin").val();
    95. if (!first_pinyin) {
    96. msg("请输入省份的拼音");
    97. return false;
    98. }
    99. let lng = $("#lng").val();
    100. if (!lng) {
    101. msg("请输入精度");
    102. return false;
    103. }
    104. let lat = $("#lat").val();
    105. if (!lat) {
    106. msg("请输入维度");
    107. return false;
    108. }
    109. // 增加省接口:http://admin.ouyangke.cn/index.php/api/index/prov_add
    110. //获取数据
    111. // $.ajax({
    112. // url: "http://admin.ouyangke.cn/index.php/api/index/prov_one?area_id",
    113. // type: "POST",
    114. // async: true,
    115. // dataType: "json",
    116. // // success :function(){
    117. // // },
    118. // success(data) {
    119. // if (data.code == 0) {
    120. // alert("success");
    121. // } else {
    122. // alert("添加失败,请重试111111");
    123. // return false;
    124. // }
    125. // },
    126. // complete(data) {
    127. // console.log(data);
    128. // },phone.slice(-6)
    129. // });
    130. let area_id = window.location.search;
    131. area_id = area_id.slice(-6);
    132. alert(area_id);
    133. //修改数据
    134. $.ajax({
    135. url: "http://admin.ouyangke.cn/index.php/api/index/prov_edit",
    136. type: "POST",
    137. data: {
    138. area_id: area_id,
    139. area_name: area_name, // 第一个area_name接口的参数(下标)
    140. pinyin: pinyin,
    141. first_pinyin: first_pinyin,
    142. lng: lng,
    143. lat: lat,
    144. },
    145. dataType: "json",
    146. success(data) {
    147. console.log(data);
    148. if (data.code == 0) {
    149. window.location.href = "6.html";
    150. } else {
    151. msg("修改失败,请重试");
    152. return false;
    153. }
    154. },
    155. });
    156. });
    157. function msg(text) {
    158. $("#msg").text(text);
    159. $("#msg").show();
    160. }
    161. </script>
    162. </html>

    修改1修改2edit3

更多相关文章

  1. 匿名函数、箭头函数、立即执行函数和字面量
  2. 匿名函数、箭头函数和立即执行函数
  3. axios的跨域处理
  4. JS 函数的执行时机
  5. 16.【TP6学习笔记】其他通过CMD命令行的方式执行操作
  6. PHP:文件上传上传限制,文件大小不超过5M,文件后缀设置,检查图片合
  7. 详解支撑7亿用户搜索的百度图片处理收录中台
  8. 实现一个简易数字货币现货跟单机器人
  9. 自然语言处理集训营第一期

随机推荐

  1. Android 中文 API (16) ―― AnalogClock
  2. android系统开发(十)-audio移植一 .
  3. Android样式和主题(style&theme)
  4. Android对SD卡进行读写
  5. android中的基本控件
  6. Android之Handler用法总结
  7. [zz] 分析Android(安卓)根文件系统启动过
  8. Oprofile在Android中的应用
  9. Android shell 系统命令
  10. android常用框架