From ccd502c938e11bb5adad58f6dac41d3ed7f4c6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=90=E5=90=89=E4=BD=B3?= <3570974289@qq.com> Date: Thu, 21 Nov 2024 19:47:13 +0800 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 --- ...15\344\275\234\347\254\224\350\256\260.md" | 330 ++++++++++++++++++ ...\346\234\237\345\257\271\350\261\241.html" | 31 ++ ...\350\261\241\346\226\271\346\263\225.html" | 45 +++ ...\347\232\204\346\227\266\351\227\264.html" | 44 +++ ...\344\270\252\345\206\231\346\263\225.html" | 45 +++ ...\346\227\266\351\227\264\346\210\263.html" | 27 ++ ...\345\200\222\350\256\241\346\227\266.html" | 155 ++++++++ 7 files changed, 677 insertions(+) create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\344\270\216\350\212\202\347\202\271\346\223\215\344\275\234\347\254\224\350\256\260.md" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/01-\345\256\236\344\276\213\345\214\226\346\227\245\346\234\237\345\257\271\350\261\241.html" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/02-\345\270\270\350\247\201\347\232\204\346\227\245\346\234\237\345\257\271\350\261\241\346\226\271\346\263\225.html" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/03-\346\230\276\347\244\272\346\240\274\345\274\217\345\214\226\347\232\204\346\227\266\351\227\264.html" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/04-\346\227\266\351\227\264\347\232\204\345\217\246\345\244\226\344\270\200\344\270\252\345\206\231\346\263\225.html" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/05-\345\276\227\345\210\260\346\227\266\351\227\264\346\210\263.html" create mode 100644 "\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/06-\345\200\222\350\256\241\346\227\266.html" diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\344\270\216\350\212\202\347\202\271\346\223\215\344\275\234\347\254\224\350\256\260.md" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\344\270\216\350\212\202\347\202\271\346\223\215\344\275\234\347\254\224\350\256\260.md" new file mode 100644 index 0000000..88e0d56 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\344\270\216\350\212\202\347\202\271\346\223\215\344\275\234\347\254\224\350\256\260.md" @@ -0,0 +1,330 @@ +# Web APIs - 第4天 + +> 进一步学习 DOM 相关知识,实现可交互的网页特效 + +- 能够插入、删除和替换元素节点 +- 能够依据元素节点关系查找节点 + +## 日期对象 + + +掌握 Date 日期对象的使用,动态获取当前计算机的时间。 + + +ECMAScript 中内置了获取系统时间的对象 Date,使用 Date 时与之前学习的内置对象 console 和 Math 不同,它需要借助 new 关键字才能使用。 + +### 实例化 + +~~~javascript + // 1. 实例化 + // const date = new Date(); // 系统默认时间 + const date = new Date('2020-05-01') // 指定时间 + // date 变量即所谓的时间对象 + + console.log(typeof date) + + + +~~~ + +### 方法 + + + + ~~~javascript + // 1. 实例化 + const date = new Date(); + // 2. 调用时间对象方法 + // 通过方法分别获取年、月、日,时、分、秒 + const year = date.getFullYear(); // 四位年份 + const month = date.getMonth(); // 0 ~ 11 + ~~~ + + +getFullYear 获取四位年份 + +getMonth 获取月份,取值为 0 ~ 11 + +getDate 获取月份中的每一天,不同月份取值也不相同 + +getDay 获取星期,取值为 0 ~ 6 + +getHours 获取小时,取值为 0 ~ 23 + +getMinutes 获取分钟,取值为 0 ~ 59 + +getSeconds 获取秒,取值为 0 ~ 59 + +### 时间戳 + +时间戳是指1970年01月01日00时00分00秒起至现在的总秒数或毫秒数,它是一种特殊的计量时间的方式。 + +注:ECMAScript 中时间戳是以毫秒计的。 + +~~~javascript + // 1. 实例化 + const date = new Date() + // 2. 获取时间戳 + console.log(date.getTime()) +// 还有一种获取时间戳的方法 + console.log(+new Date()) + // 还有一种获取时间戳的方法 + console.log(Date.now()) + +~~~ + + +获取时间戳的方法,分别为 getTime 和 Date.now 和 +new Date() + +## DOM 节点 + +> 掌握元素节点创建、复制、插入、删除等操作的方法,能够依据元素节点的结构关系查找节点 + +回顾之前 DOM 的操作都是针对元素节点的属性或文本的,除此之外也有专门针对元素节点本身的操作,如插入、复制、删除、替换等。 + +### 插入节点 + +在已有的 DOM 节点中插入新的 DOM 节点时,需要关注两个关键因素:首先要得到新的 DOM 节点,其次在哪个位置插入这个节点。 + +如下代码演示: + +```html + +

插入节点

+

在现有 dom 结构基础上插入新的元素节点

+
+ +
+ + + + +``` + +结论: + +- `createElement` 动态创建任意 DOM 节点 + +- `cloneNode` 复制现有的 DOM 节点,传入参数 true 会复制所有子节点 + +- `appendChild` 在末尾(结束标签前)插入节点 + +再来看另一种情形的代码演示: + +```html + +

插入节点

+

在现有 dom 结构基础上插入新的元素节点

+
+ + + + +``` + +结论: + +- `createElement` 动态创建任意 DOM 节点 + +- `cloneNode` 复制现有的 DOM 节点,传入参数 true 会复制所有子节点 + +- `insertBefore` 在父节点中任意子节点之前插入新节点 + +### 删除节点 + +删除现有的 DOM 节点,也需要关注两个因素:首先由父节点删除子节点,其次是要删除哪个子节点。 + +```html + + + + + + + +``` + +结论:`removeChild` 删除节点时一定是由父子关系。 + +### 查找节点 + +DOM 树中的任意节点都不是孤立存在的,它们要么是父子关系,要么是兄弟关系,不仅如此,我们可以依据节点之间的关系查找节点。 + +#### 父子关系 + +```html + + + + + + +``` + +结论: + +- `childNodes` 获取全部的子节点,回车换行会被认为是空白文本节点 +- `children` 只获取元素类型节点 + +```html + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号课程名难度操作
1HTML初级
2CSS初级
3Web APIs中级
+ + +``` + +结论:`parentNode` 获取父节点,以相对位置查找节点,实际应用中非常灵活。 + +#### 兄弟关系 + +```html + + + + +``` + +结论: + +- `previousSibling` 获取前一个节点,以相对位置查找节点,实际应用中非常灵活。 +- `nextSibling` 获取后一个节点,以相对位置查找节点,实际应用中非常灵活。 + + + + + + + + + + + + + + diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/01-\345\256\236\344\276\213\345\214\226\346\227\245\346\234\237\345\257\271\350\261\241.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/01-\345\256\236\344\276\213\345\214\226\346\227\245\346\234\237\345\257\271\350\261\241.html" new file mode 100644 index 0000000..3a5fa38 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/01-\345\256\236\344\276\213\345\214\226\346\227\245\346\234\237\345\257\271\350\261\241.html" @@ -0,0 +1,31 @@ + + + + + + + + Document + + + + + + + + \ No newline at end of file diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/02-\345\270\270\350\247\201\347\232\204\346\227\245\346\234\237\345\257\271\350\261\241\346\226\271\346\263\225.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/02-\345\270\270\350\247\201\347\232\204\346\227\245\346\234\237\345\257\271\350\261\241\346\226\271\346\263\225.html" new file mode 100644 index 0000000..e11689d --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/02-\345\270\270\350\247\201\347\232\204\346\227\245\346\234\237\345\257\271\350\261\241\346\226\271\346\263\225.html" @@ -0,0 +1,45 @@ + + + + + + + + Document + + + + + + + \ No newline at end of file diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/03-\346\230\276\347\244\272\346\240\274\345\274\217\345\214\226\347\232\204\346\227\266\351\227\264.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/03-\346\230\276\347\244\272\346\240\274\345\274\217\345\214\226\347\232\204\346\227\266\351\227\264.html" new file mode 100644 index 0000000..6058079 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/03-\346\230\276\347\244\272\346\240\274\345\274\217\345\214\226\347\232\204\346\227\266\351\227\264.html" @@ -0,0 +1,44 @@ + + + + + + + + Document + + + + +
+ + + + + \ No newline at end of file diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/04-\346\227\266\351\227\264\347\232\204\345\217\246\345\244\226\344\270\200\344\270\252\345\206\231\346\263\225.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/04-\346\227\266\351\227\264\347\232\204\345\217\246\345\244\226\344\270\200\344\270\252\345\206\231\346\263\225.html" new file mode 100644 index 0000000..ca8cf72 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/04-\346\227\266\351\227\264\347\232\204\345\217\246\345\244\226\344\270\200\344\270\252\345\206\231\346\263\225.html" @@ -0,0 +1,45 @@ + + + + + + + + Document + + + + +
+ + + + \ No newline at end of file diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/05-\345\276\227\345\210\260\346\227\266\351\227\264\346\210\263.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/05-\345\276\227\345\210\260\346\227\266\351\227\264\346\210\263.html" new file mode 100644 index 0000000..a558601 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/05-\345\276\227\345\210\260\346\227\266\351\227\264\346\210\263.html" @@ -0,0 +1,27 @@ + + + + + + + + Document + + + + + + + \ No newline at end of file diff --git "a/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/06-\345\200\222\350\256\241\346\227\266.html" "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/06-\345\200\222\350\256\241\346\227\266.html" new file mode 100644 index 0000000..4a62da4 --- /dev/null +++ "b/\344\271\220\345\220\211\344\275\263/20241121\346\227\266\351\227\264\344\270\216\345\257\271\350\261\241\347\273\203\344\271\240/\346\227\266\351\227\264\345\257\271\350\261\241\347\273\203\344\271\240/06-\345\200\222\350\256\241\346\227\266.html" @@ -0,0 +1,155 @@ + + + + + + + + + Document + + + + +
+

今天是11月21日星期六

+

下课倒计时

+

+ 00 + : + 25 + : + 20 +

+

17:40:00下课

+
+ + + + \ No newline at end of file -- Gitee