From e1fc1968ab26319f4905fc8ded42337f582afd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=BE=89?= <11764079+elrianode@user.noreply.gitee.com> Date: Tue, 12 Dec 2023 02:36:26 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张辉 <11764079+elrianode@user.noreply.gitee.com> --- .../20231211 jQuery.md" | 258 ++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 "01 \345\274\240\350\276\211/20231211 jQuery.md" diff --git "a/01 \345\274\240\350\276\211/20231211 jQuery.md" "b/01 \345\274\240\350\276\211/20231211 jQuery.md" new file mode 100644 index 0000000..b93e3a6 --- /dev/null +++ "b/01 \345\274\240\350\276\211/20231211 jQuery.md" @@ -0,0 +1,258 @@ +# 笔记 + +## jQuery + +什么是 jQuery ? + +jQuery 是一个 JavaScript 函数库。 + +jQuery 是一个轻量级的"写的少,做的多"的 JavaScript 库。 + +jQuery 库包含以下功能: + +- HTML 元素选取 +- HTML 元素操作 +- CSS 操作 +- HTML 事件函数 +- JavaScript 特效和动画 +- HTML DOM 遍历和修改 +- AJAX +- Utilities + +**提示:** 除此之外,jQuery 还提供了大量的插件。 + +# jQuery 语法 + +------ + +通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行"操作"(actions)。 + +------ + +jQuery 语法是通过选取 HTML 元素,并对选取的元素执行某些操作。 + +基础语法: $(selector).action() + +- 美元符号定义 jQuery +- 选择符(selector)"查询"和"查找" HTML 元素 +- jQuery 的 action() 执行对元素的操作 + +# jQuery 选择器 + +------ + +jQuery 选择器允许您对 HTML 元素组或单个元素进行操作。 + +------ + +jQuery 选择器允许您对 HTML 元素组或单个元素进行操作。 + +jQuery 选择器基于元素的 id、类、类型、属性、属性值等"查找"(或选择)HTML 元素。 它基于已经存在的 [CSS 选择器](https://www.runoob.com/cssref/css-selectors.html),除此之外,它还有一些自定义的选择器。 + +jQuery 中所有选择器都以美元符号开头:$()。 + +## 什么是事件? + +页面对不同访问者的响应叫做事件。 + +事件处理程序指的是当 HTML 中发生某些事件时所调用的方法。 + +实例: + +- 在元素上移动鼠标。 +- 选取单选按钮 +- 点击元素 + +在事件中经常使用术语"触发"(或"激发")例如: "当您按下按键时触发 keypress 事件"。 + +常见 DOM 事件: + +| 鼠标事件 | 键盘事件 | 表单事件 | 文档/窗口事件 | +| :----------------------------------------------------------- | :----------------------------------------------------------- | :-------------------------------------------------------- | :-------------------------------------------------------- | +| [click](https://www.runoob.com/jquery/event-click.html) | [keypress](https://www.runoob.com/jquery/event-keypress.html) | [submit](https://www.runoob.com/jquery/event-submit.html) | [load](https://www.runoob.com/jquery/event-load.html) | +| [dblclick](https://www.runoob.com/jquery/event-dblclick.html) | [keydown](https://www.runoob.com/jquery/event-keydown.html) | [change](https://www.runoob.com/jquery/event-change.html) | [resize](https://www.runoob.com/jquery/event-resize.html) | +| [mouseenter](https://www.runoob.com/jquery/event-mouseenter.html) | [keyup](https://www.runoob.com/jquery/event-keyup.html) | [focus](https://www.runoob.com/jquery/event-focus.html) | [scroll](https://www.runoob.com/jquery/event-scroll.html) | +| [mouseleave](https://www.runoob.com/jquery/event-mouseleave.html) | | [blur](https://www.runoob.com/jquery/event-blur.html) | [unload](https://www.runoob.com/jquery/event-unload.html) | +| [hover](https://www.runoob.com/jquery/event-hover.html) | | | | + +# 作业 + +```js +$(document).ready(() => { + /** + * 目标1:渲染图书列表 + * 1.1 获取数据 + * 1.2 渲染数据 + */ + /** + * 1.通过接口获取数据 + * 2.将获取到的数据转换成需要的格式 + * 3.渲染 + */ + const creator = 'mockQ' + // 获取tbody + // const tbody = document.querySelector('.list') + const tbody = $('.list') + // console.log(tbody) + function render() { + // 通过接口获取数据 + $.ajax({ + url: 'https://hmajax.itheima.net/api/books', + type: 'get', + data: { + creator + }, + // 成功时执行以下操作 + success: result => { + // console.log(result.data) + const list = result.data + // 用jQuery的html方法和map方法将获得的数据进行格式化然后填充到主体中 + tbody.html($.map(list, (ele, index) => { + const { author, bookname, id, publisher } = ele + return ` +