From 2ed95c8bbff578950ec6430fe60ae5c156c0b1f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=A9=AC=E5=AE=8F=E8=BE=BE?=
<12071445+ma-hongda@user.noreply.gitee.com>
Date: Thu, 14 Dec 2023 04:29:50 +0000
Subject: [PATCH] =?UTF-8?q?1213=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 马宏达 <12071445+ma-hongda@user.noreply.gitee.com>
---
.../1213.md" | 192 ++++++++++++++++++
1 file changed, 192 insertions(+)
create mode 100644 "48 \351\251\254\345\256\217\350\276\276/1213.md"
diff --git "a/48 \351\251\254\345\256\217\350\276\276/1213.md" "b/48 \351\251\254\345\256\217\350\276\276/1213.md"
new file mode 100644
index 0000000..5c4f3d3
--- /dev/null
+++ "b/48 \351\251\254\345\256\217\350\276\276/1213.md"
@@ -0,0 +1,192 @@
+# 笔记
+
+$.trim(对象) //去除字符串两端的空格
+
+$.map(data,(item)=>{})$.each(对象) //遍历一个数组或对象,for循环
+
+$.inArray(对象) //返回一个值在数组中的索引位置,不存在返回-1
+
+$.grep() //返回数组中符合某种标准的元素
+
+$.extend() //将多个对象,合并到第一个对象
+
+$.makeArray() //将对象转化为数组
+
+$.type() //判断对象的类别(函数对象、日期对象、数组对象、正则对象等等
+
+$.isArray() //判断某个参数是否为数组
+
+$.isEmptyObject() //判断某个对象是否为空(不含有任何属性)
+
+$.isFunction() //判断某个参数是否为函数
+
+$.isPlainObject() //判断某个参数是否为用"{}"或"new Object"建立的对象
+
+$.support() //判断浏览器是否支持某个特性
+
+# 作业
+
+```js
+const creator = 'cheng';
+
+function render() {
+ $.ajax({
+ url: 'https://hmajax.itheima.net/api/books',
+ type: 'get',
+ data: {
+ creator
+ },
+ success: (result) => {
+ const data = result.data;
+ $('tbody').html(
+ data.map((item, index) => {
+ const {id, bookname, author, publisher} = item;
+ return `
+ ${index + 1} |
+ ${bookname} |
+ ${author} |
+ ${publisher} |
+
+ 删除
+ 编辑
+ |
+
`
+ }).join(''))
+ },
+ error: error => {
+ console.log(error)
+ }
+ })
+
+}
+
+render();
+const addModal = $('.add-modal')[0];
+const newAddModal = new bootstrap.Modal(addModal)
+//添加里的保存单机事件
+$('.add-btn').bind('click', () => {
+ const form = $('.add-form')[0];
+ const book = serialize(form, {hash: true, empty: true});
+ $.ajax({
+ url: 'https://hmajax.itheima.net/api/books',
+ type: 'post',
+ data: {
+ creator,
+ ...book
+ },
+ success: () => {
+ form.reset();
+ newAddModal.hide();
+ render();
+ },
+ error: (error) => {
+ console.log(error)
+ }
+ }
+ )
+
+})
+//删除单机事件
+$('tbody ').on('click', '.del', function () {
+ const id = $(this).parent().data('id');
+ if (!confirm('是否要删除')) {
+ return 0;
+ } else {
+ $.ajax({
+ url: 'https://hmajax.itheima.net/api/books/' + id,
+ type: 'delete',
+ success: () => {
+ render();
+ },
+ error: (error) => {
+ console.log(error);
+ }
+ })
+ }
+}).on('click', '.edit', function () {
+ const id = $(this).parent().data('id');
+ const editModal = $('.edit-modal');
+ const newModal = new bootstrap.Modal(editModal);
+ newModal.show();
+ const form = $('.edit-form')[0];
+ $.ajax({
+ url: 'https://hmajax.itheima.net/api/books/' + id,
+ type: 'get',
+ success: (result) => {
+ const {bookname, author, publisher} = result.data
+ $('.bookname')[1].value = bookname;
+ $('.author')[1].value = author;
+ $('.publisher')[1].value = publisher;
+ },
+ error: (error) => {
+ console.log(error)
+ }
+ })
+ $('.edit-btn').bind('click', () => {
+ const book = serialize(form, {hash: true, empty: true});
+ console.log(book)
+ $.ajax({
+ url: "https://hmajax.itheima.net/api/books/" + id,
+ type: 'put',
+ data: {
+ creator,
+ ...book,
+ },
+ success: () => {
+ newModal.hide();
+ render();
+ },
+ error: (error) => {
+ console.log(error)
+ }
+ })
+ })
+})
+```
+
+```js
+function getSliderData(index) {
+ let newIndex = index % sliderData.length;
+ let a = sliderData[newIndex % sliderData.length];
+ $('.slider-wrapper img')[0].src = a.url;
+ $('.slider-footer p')[0].innerHTML = a.title;
+ $('.slider-footer')[0].style.backgroundColor = a.color;
+ $('.slider-indicator .active')[0].classList.remove('active');
+ $('.slider-indicator li')[newIndex].classList.add('active');
+}
+
+let index = 0;
+
+let interval = setInterval(function () {
+ getSliderData(index);
+ index++;
+}, 1000)
+function prev() {
+ index--;
+ if (index <= 0) {
+ index = sliderData.length
+ }
+ getSliderData(index);
+}
+
+function next() {
+ index++;
+ getSliderData(index);
+}
+
+$('.toggle').on('click', '.prev', function () {
+ prev();
+}).on('click', '.next', function () {
+ next();
+})
+
+$('tbody').ready(
+ $('.slider').mouseenter(function (){
+ console.log(123)
+ clearInterval(interval);
+}).mouseleave(function (){
+ interval=setInterval(function () {
+ index++;
+ getSliderData(index);
+ }, 1000)
+ }));
--
Gitee