fengchuanyu 1 долоо хоног өмнө
parent
commit
cdbd8360d3

+ 52 - 0
3_JavaScript/17_对象.html

@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // 对象中也是存储多个值 
+        // 对象中内容的形式 是 键值对. key:value 每一对后面以逗号结束
+        var person = {
+            name:"张三",
+            age:"18"
+        }
+        
+        var goods = {
+            img:"./img/a.png",
+            title:"xiaomi",
+            desc:"xxxxx"
+        }
+
+        // 对象中可以放置任何一种类型
+        var video = {
+            title:"xxxxx",
+            like:100,
+            show:true,
+            talk:["xxxx","xxxx","xxx"]
+        }
+        // 如果对象中出现函数 那么称为对象方法
+        // var person2 = {
+        //     name:"李四",
+        //     age:18,
+        //     say:function(){
+        //         console.log("hello");
+        //     }
+        // }
+
+        // 如何调用对象中的值 和 方法
+        // 在对象中调用属性或方法 使用"."链接符号
+        var person2 = {
+            name:"李四",
+            age:18,
+            say:function(){
+                console.log("hello");
+            }
+        }
+        console.log(person2.name);
+        person2.say();  
+    </script>
+</body>
+</html>

+ 43 - 0
3_JavaScript/18_字符对象.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // 字符型对应的js内部顶级对象 String
+        var str = "hello";
+        var str2 = "world";
+        // 获取制定位置的字符 字符串起始位置是0
+        console.log( str.charAt(0) );
+        // 拼接字符串
+        console.log(str.concat(str2));
+        // 返回某个指定的字符串值在字符串中首次出现的位置。如果没有包含这个字符返回-1
+        console.log(str.indexOf("w"));
+        // 查找字符串中是否包含指定的子字符串。
+        console.log(str.includes("hl"));
+        // 提取字符串的片断,并在新的字符串中返回被提取的部分。
+        // 第一个参数开始位置 第二参数结束位置(不包含结束位置)
+        // 如果第二个参数不写截取到最后
+        console.log(str.slice(1,4));
+        // 从起始索引号提取字符串中指定数目的字符。
+        // 第二个参数为截取个数
+        console.log(str.substr(1,4))
+        // trim 去除左右两边空格
+        var str3 = "  你好  ";
+        console.log(str3);
+        console.log(str3.trim());
+        // 把字符串分割为字符串数组。
+        var str4 = "2026-1-9";
+        console.log(str4.split("-"));
+        var str5 = "abcdefg";
+        console.log(str5.split(""));
+        // 获取字符串长度
+        console.log(str.length);
+        
+        
+    </script>
+</body>
+</html>