From d9bdb786505848d8aea4328f0a0ea27bfde8c0b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=91=A8=E4=BA=9A=E8=BE=89?= <3192667214@qq.com>
Date: Mon, 11 Dec 2023 16:12:40 +0000
Subject: [PATCH] =?UTF-8?q?41=20=E5=91=A8=E4=BA=9A=E8=BE=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 周亚辉 <3192667214@qq.com>
---
...41\347\220\206\347\263\273\347\273\237.md" | 145 ++++++++++++++++++
1 file changed, 145 insertions(+)
create mode 100644 "41 \345\221\250\344\272\232\350\276\211/20231210 js \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md"
diff --git "a/41 \345\221\250\344\272\232\350\276\211/20231210 js \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/41 \345\221\250\344\272\232\350\276\211/20231210 js \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md"
new file mode 100644
index 0000000..1174f10
--- /dev/null
+++ "b/41 \345\221\250\344\272\232\350\276\211/20231210 js \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md"
@@ -0,0 +1,145 @@
+# 笔记:
+
+```
+// bootstrap对象
+const modal = new bootstrap.Modal(元素)
+// 显示的方法
+modal.show()
+// 关闭的方法
+modal.hide()
+
+confirm('提示框文案') // 弹出提示窗判断是否执行操作,返回true/false
+```
+
+作业:
+
+```
+/**
+ * 目标1:渲染图书列表
+ * 1.1 获取数据
+ * 1.2 渲染数据
+ */
+const list=document.querySelector('.list')
+const creator='会上树的猪'
+function render(){
+axios({
+ url:'https://hmajax.itheima.net/api/books',
+ params:{
+ creator
+ }
+ }).then(result=>{
+ console.log(result.data.data)
+ const test=result.data.data
+
+ list.innerHTML= test.map((e,i)=>{
+ const{author,bookname,id,publisher}=e
+ return `
+
+ ${i+1} |
+ ${bookname} |
+ ${author} |
+ ${publisher} |
+
+ 删除
+ 编辑
+ |
+
`}
+ ).join('')
+
+
+ })
+}
+render()
+
+//2.添加
+const add=document.querySelector('.add-modal')
+// const addm = new bootstrap.Modal(add)
+const addm = new bootstrap.Modal(add)
+
+
+
+ const abtn=document.querySelector('.add-btn')
+ abtn.addEventListener('click',()=>{
+ const form=document.querySelector('.add-form')
+ const book=serialize(form,{hash:true,empty:true})
+ axios({
+ url: 'http://hmajax.itheima.net/api/books',
+ method: 'POST',
+ data:{
+ ...book,
+ creator
+ }
+ }).then(result=>{
+ console.log(result)
+ render()
+ form.reset()
+ addm.hide()
+ })
+
+
+ })
+
+//3.删除
+list.addEventListener('click',function(e){
+ if(e.target.className==='del'){
+ const id= e.target.dataset.id
+ console.log(e.target.dataset.id)
+ axios({
+ url: `https://hmajax.itheima.net/api/books/${id}`,
+ method:'DELETE'
+ }).then(result=>{
+ render()
+ })
+ }
+})
+//修改
+const edit=document.querySelector('.edit-modal')
+const editm = new bootstrap.Modal(edit)
+
+list.addEventListener('click',function(e){
+ if(e.target.className==='edit'){
+ editm.show()
+ const id= e.target.dataset.id
+ console.log(e.target.dataset.id)
+ axios({
+ url: `https://hmajax.itheima.net/api/books/${id}`,
+
+ }).then(result=>{
+ console.log(result.data.data)
+ let re=result.data.data
+ const{author,bookname,id,publisher}=re
+ console.log(author)
+ const editForm=document.querySelector('.edit-form')
+ const bookName1= editForm.querySelector('[name=bookname]')
+ const author1= editForm.querySelector('[name=author]')
+ const publisher1= editForm.querySelector('[name=publisher]')
+ // console.log(bookName1)
+ bookName1.value=bookname
+ author1.value=author
+ publisher1.value=publisher
+
+
+ const ebtn=document.querySelector('.edit-btn')
+ ebtn.addEventListener('click',function(e){
+ console.log(1)
+ const book=serialize(editForm,{hash:true,empty:true})
+ axios({
+ url:`https://hmajax.itheima.net/api/books/${id}`,
+ method:'put',
+ data:{
+ ...book,
+ creator
+ }
+ }).then(result=>{
+ console.log(result)
+ editm.hide()
+ render()
+ })
+
+ })
+ })
+
+ }
+
+})
+```
\ No newline at end of file
--
Gitee