zoukankan      html  css  js  c++  java
  • 2 js的20/80关键知识

    1.

     

    2

    var a = 1;
    undefined
    a
    1
    alert(a);
    undefined
    

      

     

    var b = true;
    var c = "Hi";
    undefined
    alert(b);
    alert(c);
    undefined
    

      

    function foo(bar){
    	alert(bar);
    	return bar;
    }
    undefined
    var z = foo("Hi");
    undefined
    z
    "Hi"
    

      

    function foo(bar)
    {
    	alert(bar);
    	return bar;
    }
    

      

    • shift+enter 换行

     

    function foo(bar){
    	if (bar > 3){
    		alert(bar + 1);
    	} else {
    		alert("Not enough");
    	}
    }
    undefined
    foo(5)
    undefined
    foo(2);
    undefined
    

      

     

    3

     

     

    var arr = []
    undefined
    
    function foo(bar){
    	if (bar > 3){
    		arr.push(bar);
    	} else {
    		alert("Not enough");
    		}
    }
    undefined
    
    foo(2);
    undefined
    
    foo(6);
    undefined
    arr;
    [6]
    

      

     

    var o = {
    	one:1,
    	two:2
    }
    undefined
    o.one
    1
    o.two
    2
    

      

    4

     

     

    document
    #document
    
    document.querySelector("#sidebar")
    <div id=​"sidebar">​…​</div>​
    
    var el = document.querySelector("#sidebar");
    undefined
    
    el
    <div id=​"sidebar">​…​</div>​
    
    el.setAttribute("style","display:none;")
    undefined
    

      

     

    5.

    https://developer.mozilla.org/zh-CN/docs/Web/Reference/API

    6

     

     

    var b=document.querySelector("body")
    undefined
    
    b.setAttribute("style","background-color: black");
    undefined
    

      

    var dark = "background-color: black; color: white;";
    var day = "background-color: white; color: black;";
    
    // var theme = {
    //   dark : "background-color:black; color:white; ",
    //   light : "background-color:white; color:black; "
    // };
    
    var button = document.querySelector(".nav");
    var web = document.querySelector("body");
    
    function lightSwitch() {
      if (web.style.cssText == dark){
          web.style.cssText = day;
          alert("Light Day");
      } else {
          web.style.cssText = dark;
          alert("Dark Day");
      }
    }
    
    button.onclick = lightSwitch
    

      

  • 相关阅读:
    【go语言学习】标准库之time
    【go语言学习】文件操作file
    【go语言学习】反射reflect
    【go语言学习】通道channel
    soap添加
    ubuntu apache 启用gzip
    git 版本回退
    ubuntu打开crontab日志及不执行常见原因
    Ionic3 怎么打开第三方 app,最简单粗暴的方法
    Windows安装使用Openssl创建pks p12证书
  • 原文地址:https://www.cnblogs.com/venicid/p/8158413.html
Copyright © 2011-2022 走看看