zoukankan      html  css  js  c++  java
  • js、dom基础知识

    1. 事件 onclick onmouseover等

    <button onclick="displayDate()">现在的时间是?</button>
    
      function displayDate(){alert("date");}
    

    2. 类型

    typeof "John"                 // 返回 string 
    typeof 3.14                   // 返回 number
    typeof NaN                    // 返回 number
    typeof false                  // 返回 boolean
    typeof [1,2,3,4]              // 返回 object
    typeof {name:'John', age:34}  // 返回 object
    typeof new Date()             // 返回 object
    typeof function () {}         // 返回 function
    typeof myCar                  // 返回 undefined (如果 myCar 没有声明)
    typeof null                   // 返回 object
    

    3. 如何看一个类型是不是数组,可以通过构造函数来判断。

    "John".constructor                 // 返回函数 String()  { [native code] }
    (3.14).constructor                 // 返回函数 Number()  { [native code] }
    false.constructor                  // 返回函数 Boolean() { [native code] }
    [1,2,3,4].constructor              // 返回函数 Array()   { [native code] }
    {name:'John', age:34}.constructor  // 返回函数 Object()  { [native code] }
    new Date().constructor             // 返回函数 Date()    { [native code] }
    function () {}.constructor         // 返回函数 Function(){ [native code] }
    
    var fruits = ["Banana", "Orange", "Apple", "Mango"];
    document.getElementById("demo").innerHTML = isArray(fruits);
    function isArray(myArray) {
        return myArray.constructor.toString().indexOf("Array") > -1;
    }
    

    4.类型转换

     

    //转为字符串
    let x=55;
    var t = x.toString();
    var t = String(x);
    var t = ""+x;
    
    //字符串转为数字
    x = parseInt(t);
    x = parseFloat(t);
    
  • 相关阅读:
    centos6.3 配置防火墙,开启80端口、3306端口
    Unable to run man pages on Centos 6
    1. 信息系统基础知识
    2. 软件工程
    CommonJs
    软考资料
    Node.js资料
    qyqt5(一)
    tf源码中的object_detection_tutorial.ipynb文件
    分类结果的评价指标
  • 原文地址:https://www.cnblogs.com/dongfangchun/p/8043601.html
Copyright © 2011-2022 走看看