diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/hero.css" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/hero.css" new file mode 100644 index 0000000000000000000000000000000000000000..aeb56ebc41712b1945660f9e7465b34825cfcf3c --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/hero.css" @@ -0,0 +1,56 @@ +* { + margin: 0; + padding: 0; +} + +ul { + list-style: none; +} + +a { + width: 150px; + height: 30px; + text-decoration: none; + display: block; + margin: 10px auto; + background: goldenrod; + color: #fff; + border-radius: 15px; + line-height: 30px; +} + +a:hover { + background: gold; + color: #666; +} + +body { + background: #000; + text-align: center; +} + +.list { + display: flex; + flex-wrap: wrap; + width: 500px; + margin: 20px auto; +} + +.list li { + position: relative; + transition: all 1s; + margin-top: 15px; +} + +.list li:first-child { + margin-left: 0; +} + +.list li:hover { + transform: scale(1.3); + z-index: 999; +} + +.list li img { + width: 100px; +} \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/01.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/01.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..013418af4a5b633283c7929ec4dcdcbce67d7d53 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/01.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/02.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/02.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..c3db7071cba5ed750a9f1e047542be64bbfb99e4 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/02.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/03.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/03.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..8dd48e0cd143874c199a66628dba432a87b5acde Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/03.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/04.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/04.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..703b45cfe572186ed3d20ca8acde28412280a52c Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/04.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/05.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/05.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..098236b698e56603a69399758e6ac6dbb9b804b4 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/05.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/06.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/06.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..5f650946c2ad6a398b29d5eda4d402bbc11fa0e5 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/06.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/07.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/07.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..84bacfebd91e6ff061c01f3b08a3532738226c62 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/07.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/08.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/08.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..fb3cbdadf4cd83ad98e46152fb5a2b3ee0b33b4e Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/08.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/09.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/09.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..f9885ce68ee5b297501e82b6c5ee9bce90d0a6b3 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/09.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/10.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/10.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..aa8ed9047634475be555be81574ff995dd11bc6e Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/10.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/11.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/11.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..bb6609f15d2c21b3ad03ebbabd6ff03fd0f6fc35 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/11.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/12.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/12.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..f17a900ee88c7ae285fbcb2f207f7874ced45e5a Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/12.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/13.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/13.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..20bcfbc1539057012fc54df916252860337b2c7c Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/13.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/14.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/14.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..11bd106f2b9989dad9f96bcca38eef47c746b071 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/14.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/15.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/15.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..b17917bc831faa1a82a46dbc459c3054e54163a0 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/15.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/16.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/16.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..f733ad264f3dd9d7332df475eb77da44c491679c Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/16.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/17.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/17.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..1ccad0e6c770104a46216138237ce985560b3644 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/17.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/18.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/18.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..2c35dcc05ae8a1729b94cc3e5df938f8f9cfca5a Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/18.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/19.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/19.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..df2b53e562a41b116ceea014318984b52abedfa5 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/19.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/20.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/20.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..872c8277e36a7aab626dffa48f022a79d0f989eb Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/20.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/21.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/21.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..a5300d6c2ab6dcf93e6404a6644f7b51c26b5933 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/21.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/22.jpg" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/22.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..2374e726b5bae7dad6c3b13844534f5bdfe99920 Binary files /dev/null and "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/22.jpg" differ diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/\346\211\251\345\261\225\351\242\2302.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/\346\211\251\345\261\225\351\242\2302.html" new file mode 100644 index 0000000000000000000000000000000000000000..554ebc23b6a0fbaf7afa9d113a2a9017a745963d --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/heros/\346\211\251\345\261\225\351\242\2302.html" @@ -0,0 +1,71 @@ + + + + + + Document + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
编号科目成绩操作
1语文46删除
2英语80删除
3数学100删除
+ 暂无数据 +
+ 总分:246 + 平均分:79 +
+
+ +
+ + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\344\275\234\344\270\232.md" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..e397635b9f7cc58abce8d6ed5f04dc399e2f2246 --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\344\275\234\344\270\232.md" @@ -0,0 +1,130 @@ +主观题 + +### 练习题1: + +点名: 每次刷新网页运行, 在控制台 随机输出一位同学的名字 ["老赵", "老李", "小传", "小黑"],如果输出了,则数组中删除这个名字 + +### 练习题2: + +声明对象 + +目的: 复习对象的声明 + +要求: + +1. 声明一个变量per, 类型为对象类型 +2. 该对象的属性为性别,年龄,爱好(3个) +3. 该对象的方法有 说话, 吃饭(2个) +4. 在控制台分别调用该对象的属性和方法 + +### 练习题3: + +调用对象的方法 + +目的: 复习对象的使用 + +要求: + +1. 对象声明完毕后, 调用对象中的吃饭的方法 +2. 提示: 对象中的方法本质是函数, 调用需要加() +3. 方法也可以传递参数的 + + + +### 练习题4: + +猜数字游戏,设定次数,最多猜8次 + + + +。 + +### 拓展作业1 + +**需求:** 利用对象数组渲染英雄列表案例 + +**展示效果:**如下: + +![67332737198](assets/1673327371980.png) + +功能1: + +1. 利用对象数组里面的数据来渲染页面,渲染多个数据 +2. 鼠标经过停留会显示`英雄名字` + +数据: + +~~~javascript +let datas = [ + { name: '司马懿', imgSrc: '01.jpg' }, + { name: '女娲', imgSrc: '02.jpg' }, + { name: '百里守约', imgSrc: '03.jpg' }, + { name: '亚瑟', imgSrc: '04.jpg' }, + { name: '虞姬', imgSrc: '05.jpg' }, + { name: '张良', imgSrc: '06.jpg' }, + { name: '安其拉', imgSrc: '07.jpg' }, + { name: '李白', imgSrc: '08.jpg' }, + { name: '阿珂', imgSrc: '09.jpg' }, + { name: '墨子', imgSrc: '10.jpg' }, + { name: '鲁班', imgSrc: '11.jpg' }, + { name: '嬴政', imgSrc: '12.jpg' }, + { name: '孙膑', imgSrc: '13.jpg' }, + { name: '周瑜', imgSrc: '14.jpg' }, + { name: 'XXX', imgSrc: '15.jpg' }, + { name: 'XXX', imgSrc: '16.jpg' }, + { name: 'XXX', imgSrc: '17.jpg' }, + { name: 'XXX', imgSrc: '18.jpg' }, + { name: 'XXX', imgSrc: '19.jpg' }, + { name: 'XXX', imgSrc: '20.jpg' } +] +~~~ + + + +### 拓展作业2 + +需求: 根据数据完成表格渲染 + +效果如下: + +![67332719365](assets/1673327193659.png) + +功能需求: + +1. 表格行要求 编号、科目、成绩、和 删除链接 +2. 最后计算出总分 和 平均分 + +数据如下: + +~~~javascript +let data = [ + { subject: '语文', score: 46 }, + { subject: '数学', score: 80 }, + { subject: '英语', score: 100 }, +] +~~~ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2301.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2301.html" new file mode 100644 index 0000000000000000000000000000000000000000..a0a19978a66a35c20cec53e4d3b5af976244c81d --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2301.html" @@ -0,0 +1,110 @@ + + + + + + + 渲染英雄列表案例 + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2302.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2302.html" new file mode 100644 index 0000000000000000000000000000000000000000..e17ab2548298a9ff82e384bf2669166221c12946 --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\346\211\251\345\261\225\351\242\2302.html" @@ -0,0 +1,104 @@ + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\254\224\350\256\260.md" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..1318e292aed60e5356b8daf865393c1e9540f0c0 --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\254\224\350\256\260.md" @@ -0,0 +1,334 @@ +# JavaScript 基础 - 第5天 + +> 知道对象数据类型的特征,能够利用数组对象渲染页面 + +- 理解什么是对象,掌握定义对象的语法 +- 掌握数学对象的使用 + +## 对象 + +> 对象是 JavaScript 数据类型的一种,之前已经学习了数值类型、字符串类型、布尔类型、undefined。对象数据类型可以被理解成是一种数据集合。它由属性和方法两部分构成。 + +### 语法 + +声明一个对象类型的变量与之前声明一个数值或字符串类型的变量没有本质上的区别。 + +```html + + + + + JavaScript 基础 - 对象语法 + + + + + + +``` + +### 属性和访问 + +数据描述性的信息称为属性,如人的姓名、身高、年龄、性别等,一般是名词性的。 + +1. 属性都是成 对出现的,包括属性名和值,它们之间使用英文 `:` 分隔 +2. 多个属性之间使用英文 `,` 分隔 +3. 属性就是依附在对象上的变量 +4. 属性名可以使用 `""` 或 `''`,一般情况下省略,除非名称遇到特殊符号如空格、中横线等 + +```html + + + + + JavaScript 基础 - 对象语法 + + + + + + +``` + +声明对象,并添加了若干属性后,可以使用 `.` 或 `[]` 获得对象中属性对应的值,我称之为属性访问。 + +```html + + + + + JavaScript 基础 - 对象语法 + + + + + + +``` + +扩展:也可以动态为对象添加属性,动态添加与直接定义是一样的,只是语法上更灵活。 + +```html + + + + + JavaScript 基础 - 对象语法 + + + + + + +``` + +### 方法和调用 + +数据行为性的信息称为方法,如跑步、唱歌等,一般是动词性的,其本质是函数。 + +1. 方法是由方法名和函数两部分构成,它们之间使用 : 分隔 +2. 多个属性之间使用英文 `,` 分隔 +3. 方法是依附在对象中的函数 +4. 方法名可以使用 `""` 或 `''`,一般情况下省略,除非名称遇到特殊符号如空格、中横线等 + +```html + + + + + JavaScript 基础 - 对象方法 + + + + + + +``` + +声明对象,并添加了若干方法后,可以使用 `.` 或 `[]` 调用对象中函数,我称之为方法调用。 + +```html + + + + + JavaScript 基础 - 对象方法 + + + + + + +``` + +扩展:也可以动态为对象添加方法,动态添加与直接定义是一样的,只是语法上更灵活。 + +```html + + + + + JavaScript 基础 - 对象方法 + + + + + + +``` + +**注:无论是属性或是方法,同一个对象中出现名称一样的,后面的会覆盖前面的。** + +### null + +null 也是 JavaScript 中数据类型的一种,通常只用它来表示不存在的对象。使用 typeof 检测类型它的类型时,结果为 `object`。 + +#### 遍历对象 + +~~~javascript +let obj = { + uname: 'pink' +} +for(let k in obj) { + // k 属性名 字符串 带引号 obj.'uname' k === 'uname' + // obj[k] 属性值 obj['uname'] obj[k] +} +~~~ + +for in 不提倡遍历数组 因为 k 是 字符串 + +## 内置对象 + +回想一下我们曾经使用过的 `console.log`,`console`其实就是 JavaScript 中内置的对象,该对象中存在一个方法叫 `log`,然后调用 `log` 这个方法,即 `console.log()`。 + +除了 `console` 对象外,JavaScritp 还有其它的内置的对象 + +### Math + +`Math` 是 JavaScript 中内置的对象,称为数学对象,这个对象下即包含了属性,也包含了许多的方法。 + +#### 属性 + +- Math.PI,获取圆周率 + +```javascript +// 圆周率 +console.log(Math.PI); +``` + +#### 方法 + +- Math.random,生成 0 到 1 间的随机数 + +```javascript +// 0 ~ 1 之间的随机数, 包含 0 不包含 1 +Math.random() +``` + +- Math.ceil,数字向上取整 + +```javascript +// 舍弃小数部分,整数部分加1 +Math.ceil(3.4) +``` + +- Math.floor,数字向下取整 + +```javascript +// 舍弃小数部分,整数部分不变 +Math.floor(4.68) +``` + +- Math.round,四舍五入取整 + +```javascript +// 取整,四舍五入原则 +Math.round(5.46539) +Math.round(4.849) +``` + +- Math.max,在一组数中找出最大的 + +```javascript +// 找出最大值 +Math.max(10, 21, 7, 24, 13) +``` + +- Math.min,在一组数中找出最小的 + +```javascript +// 找出最小值 +Math.min(24, 18, 6, 19, 21) +``` + +- Math.pow,幂方法 + +```javascript +// 求某个数的多少次方 +Math.pow(4, 2) // 求 4 的 2 次方 +Math.pow(2, 3) // 求 2 的 3 次方 +``` + +- Math.sqrt,平方根 + +```javascript +// 求某数的平方根 +Math.sqrt(16) +``` + +数学对象提供了比较多的方法,这里不要求强记,通过演示数学对象的使用,加深对对象的理解。 + diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2301.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2301.html" new file mode 100644 index 0000000000000000000000000000000000000000..6a1f58e8b3067decca1c08cd4e8b133c4d48ea4a --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2301.html" @@ -0,0 +1,20 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2302.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2302.html" new file mode 100644 index 0000000000000000000000000000000000000000..45b3192272b908435f1557bc7d9c52277bdb157a --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2302.html" @@ -0,0 +1,37 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2303.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2303.html" new file mode 100644 index 0000000000000000000000000000000000000000..7f0ebf11e5d8fbd2ebede2b84b4fd624ea7d28b7 --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2303.html" @@ -0,0 +1,32 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git "a/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2304.html" "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2304.html" new file mode 100644 index 0000000000000000000000000000000000000000..1400962411e4907c166feee2f4a932e0c80c91cf --- /dev/null +++ "b/\345\205\263\346\235\276\346\266\233/20241107js\344\270\255\347\232\204\345\257\271\350\261\241/\347\273\203\344\271\240\351\242\2304.html" @@ -0,0 +1,40 @@ + + + + + + Document + + + + + + + \ No newline at end of file