fanjialong 3 недель назад
Родитель
Сommit
225d82d65b

+ 8 - 0
js-demo/.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 6 - 0
js-demo/.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 8 - 0
js-demo/.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/js-demo.iml" filepath="$PROJECT_DIR$/js-demo.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
js-demo/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+  </component>
+</project>

+ 24 - 0
js-demo/_01_js_hello.html

@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <script src="js/index.js"></script>
+</head>
+<!--
+   body: 主要写html 代码
+   style: 主要写css 代码
+   script: 主要写JS 代码
+-->
+<body>
+
+</body>
+<script>
+    // 打印内容
+    // 如果js 代码比较少我们就直接在html 当中写就可以了
+    // 但是如果js 代码比较多, 简易大家单独抽取一个js 文件
+    // console.log("hello world")
+
+    console.log(a)
+</script>
+</html>

+ 47 - 0
js-demo/_02_js_vaiable.html

@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  // 定义name = zhangsa   定义一个age= 18
+  var name="zhangsan"
+  var age = 18
+  console.log(name);
+  console.log(age);
+
+  // 变量的值可否修改 可以修改
+  name="lisi"
+  console.log(name);
+
+  // var 修饰的变量是全局的 所有地方都可以访问的
+  {
+      var b = 10;
+      var b = 15;
+      console.log(b);
+  }
+  console.log(b);
+
+
+  // let 修饰变量他只能在对应代码块当中生效
+  {
+      let c = 18
+      console.log(c)
+  }
+  // console.log(c)
+
+  // let 修饰变量不允许重复定义相同名字 在同一作用域
+  {
+      let d = "zhangsan"
+      // let d = "lisi"
+  }
+
+  // const 修饰变量这个变量是一个常量不能够被修改
+  const f =10;
+
+</script>
+</html>

+ 31 - 0
js-demo/_03_js_type.html

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  // js 内置函数: 主要作用可以在浏览器进行弹框
+  // alert(123)
+  // 要求定义  number 类型  string 类型  null   undefined  boolean
+  // typeof 这也是js 提供内置函数 : 主要作用可以帮我们看一个变量类型
+  // typeof(123)
+  // number 数据类型
+  console.log(typeof 123)
+  console.log(typeof 3.14)
+  // string 类型
+  console.log(typeof "zhangsan")
+  console.log(typeof 'sxxxxx')
+  // boolean 类型
+  console.log(typeof true)
+  console.log(typeof false)
+  // null 类型
+  console.log(typeof null);
+  // undefined
+  var a;
+  console.log(typeof a)
+</script>
+</html>

+ 62 - 0
js-demo/_04_js_operate.html

@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  /**
+   * == 和 === 区别
+   * == 只会比较两个值是否相同
+   * === 不仅会比较值是否相同还会比较类型
+   */
+  var a = 10;
+  var b = "10";
+  console.log(a==b)    // true    相当于java 当中equlas 比较
+  console.log(a===b)   // false   相当于java 当中==
+
+
+  if (0){
+    console.log("条件成立")
+  }else{
+    console.log("条件不成立")
+  }
+
+  if (null){
+    console.log("条件成立")
+  }else{
+    console.log("条件不成立")
+  }
+
+  if (NaN){
+    console.log("条件成立")
+  }else{
+    console.log("条件不成立")
+  }
+
+  if (""){
+    console.log("条件成立")
+  }else{
+    console.log("条件不成立")
+  }
+
+  if (undefined){
+    console.log("条件成立")
+  }else{
+    console.log("条件不成立")
+  }
+
+
+  var c = "111";
+  var d = "abc11"
+  console.log(typeof c)
+  console.log(typeof parseInt(c))
+  // Nan
+  // console.log(parseInt(d))
+  // console.log(typeof parseInt(d));
+
+</script>
+</html>

+ 28 - 0
js-demo/_05_js_逻辑运算符.html

@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  // && 优先级高预||
+  // console.log(true && NaN && 0 && "")    // Nan
+  // console.log(1 && "123" && 0 && false)  //0
+  // console.log("hello" && "123" && 1 && true)  // true
+  // // 0|| Nan || ""
+  // console.log(0|| NaN || "hello" && "")  // ""
+  // //true && ""  ""
+  // // undefined ||NaN || ""
+  // console.log(undefined ||NaN || true && "")  //""
+  // console.log(true && 123 || NaN && false)  //123
+  var age = 20
+  if(age > 18){
+    console.log("成年")
+  }else{
+    console.log("未成年")
+  }
+</script>
+</html>

+ 50 - 0
js-demo/_06_if_swich_for.html

@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  var age =20
+  // if(age > 18){
+  //   console.log("成年")
+  // }
+  //
+  // if(age > 18){
+  //   console.log("成年")
+  // }else{
+  //   console.log("未成年")
+  // }
+  //
+  // if(age < 18){
+  //   console.log("青少年")
+  // }else if(age>30  &&  age<40){
+  //   console.log("中年")
+  // }else{
+  //   console.log("老年")
+  // }
+  //
+  // var day = 3
+  // switch (day) {
+  //   case 1:{
+  //     console.log("星期一")
+  //     break
+  //   }
+  //   case 2:{
+  //     console.log("星期2")
+  //     break
+  //   }
+  //   default:{
+  //     console.log("非法操作")
+  //     break
+  //   }
+  // }
+
+  for(var i = 0; i < 10; i++){
+    console.log(i)
+  }
+</script>
+</html>

+ 76 - 0
js-demo/_07_function.html

@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+    /**
+     * 定义函数
+     * function  函数名字(形参,形参){
+     *     函数体
+     * }
+     *
+     * 函数名(实际参数....)
+     *
+     *
+     * 定义一个 计算 两个整数方法
+     */
+    // function add(a,b){
+    //     console.log(a+b)
+    // }
+    // add(1,2);
+    // /**
+    //  * 定义出来4中函数类型
+    //  * 无参数 无返回值
+    //  * 有参数 无返回值
+    //  * 无参数 有返回值
+    //  * 有参数 有返回值
+    //  */
+    // // 无参数无返回值
+    // function  fun1(){
+    //     console.log(1+2)
+    // }
+    // fun1()
+    //
+    //
+    // // 有参数 无返回值
+    // function fun2(a,b){
+    //     console.log(a+b)
+    // }
+    // fun2(1,2)
+    //
+    // // 无参数 有返回值
+    // function fun3() {
+    //     return 1+2;
+    // }
+    // var ret = fun3();
+    // console.log(ret)
+    //
+    // // 有参数有返回值
+    // function fun4(a, b){
+    //     return  a+b;
+    // }
+    //
+    // console.log(fun4(1, 2));
+
+
+    /**
+     * 匿名函数
+     */
+
+
+    let f = function (){
+        console.log("这是一个匿名函数")
+    }
+    // 调用匿名函数直接用变量名字取进行调用
+    f();
+
+
+    let f1 = (a,b) => console.log(a)
+    f1("123");
+</script>
+</html>

+ 83 - 0
js-demo/_08_js_object.html

@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  /**
+   * 第一种创建对象方式
+   * js 当中创建对象不像java 一样必须要先创建一个类 然后在new 对象
+   *
+   * 在js 当中 直接{属性: xxx,属性:xxx,函数...}
+   */
+  // obj 对象有三个属性  有2个函数
+  // var obj = {
+  //   name : "zhangsan",
+  //   age : 18,
+  //   email: "123@qq.com",
+  //   eat: function (){
+  //     console.log("吃饭")
+  //   },
+  //   sleep: function (){
+  //     console.log("睡觉")
+  //   }
+  // }
+
+  // console.log(obj);
+  // // 获取对象属性
+  // // 对象.属性名
+  // console.log(obj.name);
+  // // 对数.函数名
+  // obj.sleep()
+
+  // 定义一个函数 传入一个对象, 如果对象名字等于zhangsan  就把他年龄修改成20岁
+  // function changeAge(o){
+  //   if(o.name =="zhangsan"){
+  //     o.age = 20
+  //   }
+  //   console.log(o)
+  // }
+  // changeAge(obj)
+
+  /**
+   * 创建对象第二种方式:
+   * let 对象名 = new Object();
+   * 对象名.属性名= 属性值
+   * 对象名.函数名= 函数
+   */
+
+  // let obj = new Object();
+  // obj.name="zhangsan";
+  // obj.age =18;
+  // obj.email ="!23qq.com";
+  // obj.sleep= function (){
+  //   console.log("睡觉")
+  // }
+  // console.log(obj)
+  // console.log(obj.name)
+  // obj.sleep()
+
+  /**
+   * 创建对象第三种方式 构造器方式
+   * function 构造器名字(参数){
+   *     this.属性名= 属性值
+   *     this.函数名= 函数
+   * }
+   *
+   */
+  function Dog(name,age){
+    this.name = name;
+    this.age= age;
+    this.say = function (){
+      console.log("狗叫")
+    }
+  }
+  var dog = new Dog("zhangsan",10)
+  console.log(dog.name)
+  dog.say();
+</script>
+</html>

+ 69 - 0
js-demo/_09_js_数组.html

@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+<script>
+  /**
+   * 数组 : Array
+   * 方式一: new Array(元素,...)
+   * 方式二: [元素,元素.....]
+   */
+  // var arr =new Array(1,2,3,3,4,5,6,7);
+  // for (let i = 0; i < arr.length; i++) {
+  //   console.log(arr[i])
+  // }
+  // // 使用方式二定义一个数组 如果是奇数就打印奇数如果是偶数就打印偶数
+  // var arr1 = [1,2,3,4,5,6,7,8,9]
+  // for (let i = 0; i < arr1.length; i++) {
+  //   var item = arr[i];
+  //   if(item %2 == 0){
+  //     console.log(item+"偶数")
+  //   }else{
+  //     console.log(item+"奇数")
+  //   }
+  // }
+
+
+  /**
+   * 在js 当中数组
+   * 他不出现索引越界问题
+   */
+  // var arr2 = [1,2,3]
+  // // console.log(arr2[10])
+  //
+  // arr2[10]= 5
+  // for (let i = 0; i < arr2.length; i++) {
+  //   console.log(arr2[i])
+  // }
+  // console.log(arr2.length)
+  // var arr3 = [1,2,"zhangsan"]
+  // console.log(arr3)
+
+  /**
+   * JS 数组常用属性和方法
+   * length: 查看数组的长度
+   * forEach(functjion): 遍历数组元素
+   * push(e): 往数组当中添加元素
+   * splice(index,index): 可以删除数组当中元素
+   */
+  var arr = [1,2,3,4,5,6]
+  // console.log(arr.length)
+
+  // 往数组中添加元素
+  arr.push(10)
+  // 删除元素
+  arr.splice(0,2)
+  // arr.forEach(e=>console.log(e))
+  arr.forEach(function (e){
+      console.log(e)
+  })
+
+
+
+</script>
+</html>

+ 66 - 0
js-demo/_10_window.html

@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+    <button onclick="fun()">删除</button>
+<button onclick="login()">登录</button>
+</body>
+<script>
+
+
+    function login(){
+        console.log(123)
+        // 做登录校验
+        // 获取用户输入账号
+        // 获取用户输入密码
+        // 把账号和密码发送到后端进行登录
+        // 如果后端登录没有问题 , 给他跳转首页当中
+        location.href="http://www.taobao.com"
+    }
+
+    console.log(window.location);
+    console.log(location)
+
+    /**
+     * 当点击删除按钮的时候
+     * 弹框询问是否确定删除 , 如果点击确定
+     * 弹出删除成功
+     */
+    // function fun(){
+    //   var f = confirm("确定要删除吗")
+    //   if(f){
+    //     alert("删除成功")
+    //   }else{
+    //     alert("删除失败")
+    //   }
+    // }
+
+    // window 常用方法
+    // window 的属性和方法  可以省略window
+    // alert()  在浏览器当标签页中弹框
+    // alert("")
+    // var f = confirm("确定要删除吗")
+    // console.log(f)
+
+    /**
+     * 定时器 : 可以然找你设置时间间隔 ,定期去执行相应代码
+     * 每隔1s 种会去执行function 函数代码
+     */
+    // num = 0  让num 每一秒加1  如果num = 10 停止定时器
+    // var num = 0;
+    // var timer = setInterval(function (){
+    //     num++;
+    //     console.log(num);
+    //     if(num == 10){
+    //         clearInterval(timer)
+    //     }
+    // },1000)
+
+    setTimeout(function () {
+        console.log("执行了代码")
+    }, 5000);
+</script>
+</html>

+ 88 - 0
js-demo/_11_dom_api.html

@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<!--<div id="d1">123</div>-->
+<!--<div id="d2">234</div>-->
+<!--<div id="d3">567</div>-->
+<!--<button onclick="fun()">按钮</button>-->
+<!--<form action="#">-->
+<!--    账号: <input type="text" name="username" id="username" > <br>-->
+<!--    密码: <input type="password" name="password" id="password"> <br>-->
+<!--    <input type="button" onclick="login()" value="登录">-->
+<!--</form>-->
+
+    <div id="div1">123</div>
+</body>
+
+<script>
+    /**
+     * 想要操作界面元素必须要先获取到界面元素
+     * document.getElementById("div1")
+     * 操作标签内容
+     *  元素.innnerText 获取内容
+     *   元素.innnerText = xx   设置内容
+     * 操作属性
+     *   元素.属性名     获取属性的值
+     *   元素.属性名=值  给属性设置值
+     *
+     */
+    var div = document.getElementById("div1")
+    // 设置他背景颜色为红色
+    div.style.background = "green"
+
+
+    // function login(){
+    //     // 获取账号
+    //     var usernameDiv = document.getElementById("username")
+    //     var passwordDiv = document.getElementById("password")
+    //     // console.log(usernameDiv.innerText)
+    //     // console.log(passwordDiv.innerText)
+    //     // 如果获取标签属性
+    //     /**
+    //      *
+    //      * 获取标签.属性名 获取属性值
+    //      */
+    //     // 获取input 标签的value 的属性值
+    //     console.log(usernameDiv.value);
+    //     console.log(passwordDiv.value);
+    //     // 获取密码
+    //     if(usernameDiv.value == "admin" && passwordDiv.value == "123"){
+    //         location.href = "http://www.baidu.com"
+    //     }else{
+    //         alert("账号密码错误")
+    //     }
+    // }
+
+    //当前几点按钮时候 要获取id 为d1 的标签
+    // function fun(){
+    //   /**
+    //    * 根据id 获取制定id 元素标签
+    //    * document.getElementById();
+    //    */
+    //   var div = document.getElementById("d1")
+    //   console.log(div)
+    //   // 获取到元素以后就可以获取元素内容
+    //   /**
+    //    * 元素.innerText
+    //    * 元素.innerHtml
+    //    */
+    //   console.log(div.innerText)
+    //   /**
+    //    * 修改元素内容
+    //    * div.innerText = 新的内容
+    //    */
+    //   div.innerText = "fanjialong"
+    // }
+
+    /**
+     * 创建一个登录界面
+     * 获取界面当中账号和密码
+     * 如果站好输入等于admin 密码输入等于123 表示登录成功跳转到baidu.com
+     * 否则提醒账号密码错误
+     */
+</script>
+</html>

+ 35 - 0
js-demo/_12_dom练习.html

@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<div id ="div1"></div>
+<img id="img" src="img/1.png" alt="">
+<button onclick="fun()">修改div 内容</button>
+<button onclick="fun1()">变成美女</button>
+</body>
+<script>
+    /**
+     * 需求1: 点击button 按钮. 把div 内容设置成我是中国人
+     * 需求2: 点击变成美女按钮, 把img src 属性修改成img/2.png
+     */
+    function fun(){
+        // 1 获取id 为div 元素  document.getElementById()
+        var div1 = document.getElementById("div1")
+        // 2 给元素去设置内容为我是中国中  元素.innertText
+        div1.innerText = "我是中国人"
+    }
+
+    /**
+     * dom 操作不论事操作元素本身
+     * 还是操作元素的内容 或者是属性
+     * 都必须要先获取这个元素
+     */
+    function fun1(){
+        var img = document.getElementById("img")
+        img.src = "img/2.png"
+    }
+</script>
+</html>

BIN
js-demo/img/1.png


BIN
js-demo/img/2.png


+ 8 - 0
js-demo/js-demo.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="GENERAL_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 1 - 0
js-demo/js/index.js

@@ -0,0 +1 @@
+console.log("hello wordl123")

+ 16 - 0
js-demo/test.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<div id="div1"></div>
+</body>
+
+<script>
+  setInterval(function (){
+    document.getElementById("div1").innerText = new Date().toLocaleString()
+  },1000)
+</script>
+</html>