zsydgithub 2 年之前
父節點
當前提交
6b92946f63
共有 9 個文件被更改,包括 546 次插入0 次删除
  1. 56 0
      4_js/12_数组的方法.html
  2. 108 0
      4_js/13_字符串的方法.html
  3. 101 0
      5_Bom/1.html
  4. 130 0
      5_Bom/1_test.html
  5. 51 0
      5_Bom/2.html
  6. 16 0
      5_Bom/2_弹出框.html
  7. 20 0
      5_Bom/3_history.html
  8. 45 0
      5_Bom/4_location.html
  9. 19 0
      5_Bom/test.html

+ 56 - 0
4_js/12_数组的方法.html

@@ -43,6 +43,62 @@
     // console.log(fruits)
     // console.log(fruits)
     //unshift() 方法返回新数组的长度。
     //unshift() 方法返回新数组的长度。
     // console.log(fruits.unshift("Lemon"))
     // console.log(fruits.unshift("Lemon"))
+
+    //length 属性提供了向数组追加新元素的简易方法
+    // var fruits = ["Banana", "Orange", "Apple", "Mango"];
+    // fruits[fruits.length] = "Kiwi"  
+    //fruits.length = 4     fruits[4] = 'kiwi'
+    // console.log(fruits)
+
+    //使用 delete 会在数组留下未定义的空洞。请使用 pop() 或 shift() 取而代之。
+    // var fruits = ["Banana", "Orange", "Apple", "Mango"];
+    // delete fruits[0];  
+    // console.log(fruits)
+
+    //splice() 方法可用于向数组添加新项
+    // var fruits = ["Banana", "Orange", "Apple", "Mango"];
+    // fruits.splice(2, 0, "Lemon", "Kiwi");
+    /* 第一个参数(2)定义了应添加新元素的位置(拼接)。
+    第二个参数(0)定义应删除多少元素。
+    其余参数(“Lemon”,“Kiwi”)定义要添加的新元素。
+    splice() 方法返回一个包含已删除项的数组: */
+    // console.log(fruits)
+
+    //splice()删除数组的第一项
+    // var fruits = ["Banana", "Orange", "Apple", "Mango"];
+    // fruits.splice(0, 2);
+    // console.log(fruits)
+
+    //concat() 方法通过合并(连接)现有数组来创建一个新数组
+    //concat() 方法不会更改现有数组。它总是返回一个新数组
+    // var myGirls = ["Cecilie", "Lone"];
+    // var myBoys = ["Emil", "Tobias", "Linus"];
+    // var myChildren = myGirls.concat(myBoys);
+    // console.log(myChildren)
+
+    //concat() 方法可以使用任意数量的数组参数
+    // var arr1 = ["Cecilie", "Lone"];
+    // var arr2 = ["Emil", "Tobias", "Linus"];
+    // var arr3 = ["Robin", "Morgan"];
+    // var myChildren = arr1.concat(arr2, arr3);
+    // console.log(myChildren)
+
+    //concat() 方法也可以将值作为参数
+    // var arr1 = ["Cecilie", "Lone"];
+    // var myChildren = arr1.concat(["Emil", "Tobias", "Linus"]);
+    // console.log(myChildren) 
+
+    // slice() 方法用数组的某个片段切出新数组。本例从数组元素 1 ("Orange")开始切出一段数组
+    //slice() 方法创建新数组。它不会从源数组中删除任何元素。
+    // var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
+    // var citrus = fruits.slice(1);
+    // console.log(fruits)
+    // console.log(fruits.slice(1))
+
+    //slice() 可接受两个参数,比如 (1, 3)。该方法会从开始参数选取元素,直到结束参数(不包括)为止。
+    // var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
+    // var citrus = fruits.slice(1, 3);   
+    // console.log(citrus)
   </script>
   </script>
 </body>
 </body>
 
 

+ 108 - 0
4_js/13_字符串的方法.html

@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    //length 属性返回字符串的长度
+    // var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    // var sln = txt.length;
+    // console.log(sln)
+
+    //indexOf() 方法返回字符串中指定文本首次出现的索引(位置)
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.indexOf("name");
+    // console.log(pos)
+
+    //lastIndexOf() 方法返回指定文本在字符串中最后一次出现的索引
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.lastIndexOf("China");
+    // console.log(pos)
+
+    // 如果未找到文本, indexOf() 和 lastIndexOf() 均返回 -1
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.lastIndexOf("baidu");
+    // console.log(pos)
+
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.indexOf("China", 18);
+    // console.log(pos)
+
+    // lastIndexOf() 方法向后进行检索(从尾到头),这意味着:假如第二个参数是 50,则从位置 50 开始检索,直到字符串的起点。
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.lastIndexOf("China", 50);
+    // console.log(pos)
+
+    /* 这两种方法是不相等的。区别在于:
+    search() 方法无法设置第二个开始位置参数。
+    indexOf() 方法无法设置更强大的搜索值(正则表达式) */
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.search("of");
+    // console.log(pos)
+
+    //slice() 提取字符串的某个部分并在新字符串中返回被提取的部分
+    // var str = "Apple, Banana, Mango";
+    // var res = str.slice(7, 13);
+    // console.log(res)
+
+    //如果某个参数为负,则从字符串的结尾开始计数
+    // var str = "Apple, Banana, Mango";
+    // var res = str.slice(-13, -7);
+    // console.log(res)
+
+    //substring() 类似于 slice()。不同之处在于 substring() 无法接受负的索引。
+    // var str = "Apple, Banana, Mango";
+    // var res = str.substring(7, 13);
+    // console.log(res)
+
+    // substr() 类似于 slice()。不同之处在于第二个参数规定被提取部分的长度。
+    // var str = "Apple, Banana, Mango";
+    // var res = str.substr(7, 6);
+    // console.log(res)
+
+    //replace() 方法用另一个值替换在字符串中指定的值
+    //replace() 方法不会改变调用它的字符串。它返回的是新字符串
+    // str = "Please visit Microsoft!";
+    // var n = str.replace("Microsoft", "W3School");
+    // console.log(n)
+
+    // 默认地,replace() 只替换首个匹配
+    //replace() 对大小写敏感。因此不对匹配 MICROSOFT
+    // str = "Please visit Microsoft and Microsoft!";
+    // var n = str.replace("Microsoft", "W3School");
+    // console.log(n)
+
+    //通过 toUpperCase() 把字符串转换为大写:
+    // var text1 = "Hello World!";       // 字符串
+    // var text2 = text1.toUpperCase();  // text2 是被转换为大写的 text1
+    // console.log(text2)
+
+    //通过 toLowerCase() 把字符串转换为小写:
+    // var text1 = "Hello World!";       // 字符串
+    // var text2 = text1.toLowerCase();  // text2 是被转换为小写的 text1
+    // console.log(text2)
+
+    //concat() 连接两个或多个字符串:
+    // var text1 = "Hello";
+    // var text2 = "World";
+    // text3 = text1.concat(" ", text2);
+    // console.log(text3)
+
+    //trim() 方法删除字符串两端的空白符
+    // var str = "       Hello World!        ";
+    // alert(str.trim());
+
+
+    // charAt() 方法返回字符串中指定下标(位置)的字符串
+    // var str = "HELLO WORLD";
+    // console.log(str.charAt(0))  
+  </script>
+</body>
+
+</html>

+ 101 - 0
5_Bom/1.html

@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    // var a =100
+    // function create(){
+    //   var a =200
+    //   return function(){
+    //     alert(a)
+    //   }
+    // }
+    // var fn = create()
+    // fn()
+
+    // 第一个 弹出200
+
+
+    // var a =100
+    // function invoke(fn){
+    //   var a =200
+    //   fn()
+    // }
+    // function fn(){
+    //   alert(a)
+    // }
+    // invoke(fn)
+    // //第二个 弹出100
+
+    // const obj = {
+    //   a: 100
+    // }
+    // const obj1 = obj
+    // let a1 = obj.a
+    // obj1.a = 200
+    // console.log(obj.a)
+    // console.log(a1)
+    // a1=300
+    // console.log(obj.a)
+    // console.log(obj1.a)
+
+    // 200  100  200  200
+
+
+    // 123 instanceof Number
+    // new Number(123) instanceof Number
+    // Number(123) instanceof Number
+    //都会打印出 为True
+
+
+    // function log1(){
+    //   setTimeout(()=>{
+    //     console.log(1)
+    //   },0)
+    // }
+    // function log2(){
+    //   console.log(2)
+    // }
+    // function log3(){
+    //   console.log(4)
+    //   return new Promise((reslove)=>{
+    //     console.log(5)
+    //     reslove(6)
+    //   })
+    // }
+    // log1()
+    // log2()
+    // log3().then((res)=>{
+    //   console.log(res)
+    // })
+    // 2 4 5 6 1
+
+    //Array.isArray()方法
+
+    //浅拷贝是创建一个新对象,这个对象有着原始对象属性值的一份精确拷贝。
+    // 如果属性是基本类型,拷贝的就是基本类型的值,如果属性是引用类型,拷贝的就是内存地址 。
+    // 深拷贝是将一个对象从内存中完整的拷贝一份出来,从堆内存中开辟一个新的区域存放新对象。
+    //两个都属于 浅拷贝
+
+    //实现深拷贝的方法
+    // var obj1 = {
+    //   a: 1,
+    //   b: 2,
+    //   c: 3
+    // }
+    // var objString = JSON.stringify(obj1);
+    // var obj2 = JSON.parse(objString);
+
+    
+
+  </script>
+</body>
+
+</html>

+ 130 - 0
5_Bom/1_test.html

@@ -0,0 +1,130 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <div>
+    <button id="btn1">去底部</button>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <div>hahahhhhhhhhhhhhhhhhhhhhhhh</div>
+    <button id="btn">回顶部</button>
+    <button id="btn3"> 随机数</button>
+  </div>
+  <script>
+    var btn = document.getElementById('btn')
+    var btn1 = document.getElementById('btn1')
+    var btn3 = document.getElementById('btn3')
+    btn.onclick = function () {
+      // console.log(scrollTop)
+      // scrollTo(0,30)   相对于  右侧坐标
+      // scrollBy(0,-30)   // 相对于当前本身坐标
+      var a = setInterval(function () {
+        //滚动条滚动的距离
+        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
+        if (scrollTop > 0) {
+          scrollBy(0, -30)
+          console.log(scrollTop)
+        } else  {
+          clearInterval(a)
+          console.log('我挂掉了')
+        }
+      }, 100)
+    }
+
+    btn1.onclick = function(){
+      var b = setInterval(function(){
+        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
+        if(scrollTop < 542.4000244140625){
+          scrollBy(0,30)
+          console.log(scrollTop)
+        } else{
+          clearInterval(b)
+          console.log('我挂掉了')
+        } 
+      },100) 
+    }
+    btn3.onclick = function(){
+      console.log(Math.random())//生成0-1之间的随机小数
+      // var a = setTimeout(function(){
+      //   console.log(Math.random())
+      // },5000)
+
+      //setTimeout  只执行一次
+      //setInterval  一直执行 除非清除  clearInterval 
+
+      //Math.random()
+      //Math.floor() 向下取整  和四舍五入没关系  
+      var a = setInterval(function(){
+        console.log(Math.floor(Math.random()*100))
+
+        
+      },1000)
+    }
+  </script>
+</body>
+
+</html>

+ 51 - 0
5_Bom/2.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+
+  <style>
+    .container {
+      display: flex;
+      flex-direction: column;
+    }
+    .row {
+      display: flex;
+    }
+    .row:nth-child(1) {
+      justify-content: flex-start;
+    }
+    .row:nth-child(2) {
+      justify-content: center;
+    }
+    .row:nth-child(3) {
+      justify-content: flex-end;
+    }
+    .box {
+      width: 50px;
+      height: 50px;
+      background-color: #ccc;
+      margin: 5px;
+    }
+  </style>
+</head>
+
+<body>
+  <div class="container">
+    <div class="row">
+      <div class="box"></div>
+    </div>
+    <div class="row">
+      <div class="box"></div>
+    </div>
+    <div class="row">
+      <div class="box"></div>
+    </div>
+  </div>
+
+</body>
+
+</html>

+ 16 - 0
5_Bom/2_弹出框.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  <script>
+    // alert('这是一个弹出框')//弹出消息对话框(对话框只有一个“确定”按钮)
+    // confirm('123')//弹出消息对话框(对话框内有一个“确定”按钮和一个“取消”按钮)
+    window.prompt('请输入年龄',18)//弹出消息对话框(对话框内可以输入文本,确定和取消)
+  </script>
+</body>
+</html>

+ 20 - 0
5_Bom/3_history.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  <h2>我是首页</h2>
+  <a href="test.html">附页</a>
+  <button id="btn">返回</button>
+  <script>
+    var btn = document.getElementById('btn')
+    btn.onclick = function(){
+      history.forward()
+    }
+  </script>
+</body>
+</html>

+ 45 - 0
5_Bom/4_location.html

@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    /*
+    Location 对象的属性
+
+    hash 设置或返回从井号 (#) 开始的 URL(锚)
+    host 设置或返回主机名和当前 URL 的端口号
+    hostname 设置或返回当前 URL 的主机名
+    href 设置或返回完整的 URL
+    pathname 设置或返回当前 URL 的路径部分
+    port 设置或返回当前 URL 的端口号
+    protocol 设置或返回当前 URL 的协议
+    search 设置或返回从问号 (?) 开始的 URL(查询部分)
+    Location 对象的方法
+ 
+
+
+    Navigator 对象的属性
+
+    appCodeName 返回浏览器的代码名
+    appName 返回浏览器的名称
+    appVersion 返回浏览器的平台和版本信息
+    browserLanguage 返回当前浏览器的语言
+    cookieEnabled 返回指明浏览器中是否启用 cookie 的布尔值
+    cpuClass 返回浏览器系统的 CPU 等级
+    onLine 返回指明系统是否处于脱机模式的布尔值
+    platform 返回运行浏览器的操作系统平台
+    systemLanguage 返回 OS 使用的默认语言
+    userAgent 返回由客户机发送服务器的 user-agent 头部的值
+    userLanguage 返回 OS 的自然语言设置
+    */
+  </script>
+</body>
+
+</html>

+ 19 - 0
5_Bom/test.html

@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  <h2>我是附页</h2>
+  <button id="btn">首页</button>
+  <script>
+    var btn = document.getElementById('btn')
+    btn.onclick = function(){
+      history.back()
+    }
+  </script>
+</body>
+</html>