e 5 місяців тому
батько
коміт
8845e5eb55

+ 16 - 8
js/js基础/17.demo.html

@@ -35,16 +35,24 @@
     //         break;
     // }
     //  案例2:进入页面 输入年份 页面显示当前年月及平年/闰年;
-    var year  = prompt("请输入年份");
-    console.log(year);
-    if(year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
-        alert(year + "年是闰年");
-    } else {
-        alert(year + "年是平年");
-    }
+    // var year  = prompt("请输入年份");
+    // console.log(year);
+    // if(year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
+    //     alert(year + "年是闰年");
+    // } else {
+    //     alert(year + "年是平年");
+    // }
 
     // 案例三:进入页面 输入三角形的宽高 弹出三角形的面积 函数
-    </script>
+        function fn1() {
+            var width = prompt("请输入宽度");
+            var height = prompt("请输入高度");
+            var area = (width * height) / 2;
+            alert(area);
+
+        }
+        fn1();
+     </script>
     
 </body>
 </html>

+ 23 - 0
js/js基础/18.类型.html

@@ -0,0 +1,23 @@
+<!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>
+        var arr = new Array();
+        var obj = new Object();
+        var x = new Number();
+        var y = new String();
+        var z = new Boolean();
+        console.log(arr,obj,x,y,z);
+        var a = 4.78475873;
+        // 取整
+        console.log(parseInt(a));
+        // 保留浮点数
+        console.log(parseFloat(a));
+    </script>
+</body>
+</html>

+ 39 - 0
js/js基础/19.Date对象.html

@@ -0,0 +1,39 @@
+<!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>
+        // 获取当前时间
+        var date = new Date();
+        // console.log(new Date());
+        console.log(date.getFullYear());//年份
+        console.log(date.getMonth() + 1);//月份 0-11
+        console.log(date.getDate());//日
+        console.log(date.getHours());//时
+        console.log(date.getMinutes());//分
+        console.log(date.getSeconds());//秒
+        console.log(date.getDay());//星期
+        console.log(date.getMilliseconds());//毫秒
+        console.log(date.getTime());//时间戳
+        var a = new Date("2025-01-28");
+        // console.log(a.getTime())
+        var x = date.getTime();
+        var y = a.getTime();
+        console.log(y -x); //  ms
+        var diffTime = parseInt((y-x)/1000);
+        console.log(diffTime);
+
+        var day = parseInt(diffTime / 60 / 60 / 24);
+        var hour = parseInt(diffTime / 60 / 60   % 24);
+        var minute = parseInt(diffTime / 60  % 60);
+        var second = parseInt(diffTime % 60);
+        document.write("距离过年还有"+ day +"天" + hour +"小时" + minute + "分" + second + "秒");
+
+
+    </script>
+</body>
+</html>

+ 27 - 0
js/js基础/20.Math对象.html

@@ -0,0 +1,27 @@
+<!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>
+        // 变量
+        var a = '1';
+        // 字面量 1 2 3 4 true '哈哈'
+        console.log(Math.PI);//π
+        console.log(Math.E);//常量
+        console.log(Math.pow(2,6));//x的y次幂
+        console.log(Math.ceil(12.3));//向上取整
+        console.log(Math.floor(12.4));//向下取整
+        console.log(Math.abs(-2));//绝对值
+        console.log(Math.sqrt(81));//算术平方根
+        console.log(Math.round(2.7));//四舍五入
+        console.log(Math.random()*10);//随机数
+        // 随机数x-y取整
+        // Math.round(Math.random() * (y-x) + x)
+        console.log(Math.round(Math.random() * (10-1) + 1));
+    </script>
+</body>
+</html>

+ 38 - 0
js/js基础/21.数据类型.html

@@ -0,0 +1,38 @@
+<!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>
+        /**
+         * 数据类型:
+         * 基本数据类型:
+         * null number boolean string undefined
+         *  (新增)symbol bigInt
+         * 引用数据类型
+         * Object(object,function,array)
+         * 
+         * 堆和栈:
+         * 系统进行分配
+         * 堆:引用数据类型 一般不进行改变
+         * 栈:基本数据类型  修改的地址(引用的指针)
+        */
+       var a  =10;
+       var b = a;
+       b = 15;
+       console.log(a,b);
+
+       var mm = {
+        aa:20,
+        bb:19
+       }
+       var nn = mm;
+       nn.aa = 30;
+       console.log(mm,'mm');
+       console.log(nn,'nn')
+    </script>
+</body>
+</html>