diff --git "a/33\351\227\253\347\273\247\345\221\250/20231208\345\233\276\344\271\246\347\256\241\347\220\206.md" "b/33\351\227\253\347\273\247\345\221\250/20231208\345\233\276\344\271\246\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..ea30c049dfa8051d892658e1e4245a6a7d94af58 --- /dev/null +++ "b/33\351\227\253\347\273\247\345\221\250/20231208\345\233\276\344\271\246\347\256\241\347\220\206.md" @@ -0,0 +1,112 @@ +# 笔记 + +```js +// bootstrap对象 +const modal = new bootstrap.Modal(元素) +// 显示的方法 +modal.show() +// 关闭的方法 +modal.hide() + +confirm('提示框文案') // 弹出提示窗判断是否执行操作,返回true/false +``` + + + +# 作业 + +```js +const list = document.querySelector('.list') +const author = 'kjinkjin' +show() + + +document.querySelector('.add-btn').addEventListener('click', e => { + const addform = document.querySelector('.add-form') + const { bookname, author, publisher } = serialize(addform, true, true) + axios({ + url: 'http://ajax-api.itheima.net/api/books', + method: 'post', + author, + data: { bookname, author, publisher } + }) + show() +}) + + +list.addEventListener('click', e => { + const tar = e.target + const id = tar.parentNode.dataset.id + if (tar.className == 'del') { + axios({ + url: `http://ajax-api.itheima.net/api/books/${id}`, + method: 'delete' + }).then(e => { + show() + }) + } + + + if (tar.className == 'edit') { + const edit = document.querySelector('.edit-modal') + const editmodal = new bootstrap.Modal(edit) + axios({ + url: `http://ajax-api.itheima.net/api/books/${id}` + }).then(e => { + const data = e.data.data + const editform = document.querySelector('.edit-form') + const { bookname, author, publisher } = editform + bookname.value = data.bookname + author.value = data.author + publisher.value = data.publisher + editmodal.show() + document.querySelector('.edit-btn').addEventListener('click', e => { + const {bookname, author, publisher } = serialize(editform,true,true) + axios({ + url: `http://ajax-api.itheima.net/api/books/${id}`, + method: 'put', + data:{ + bookname, + author, + publisher + } + }).then(e => { + show() + editmodal.hide() + console.log(e); + }) + }) + + }) + } +}) + + + + + + +function show() { + const lost = document.querySelector('.list') + let str = '' + axios({ + url: 'http://ajax-api.itheima.net/api/books' + }).then((e, i) => { + e.data.data.forEach((e, i) => { + str += `