zoukankan      html  css  js  c++  java
  • jquery判断节点存在

    var id = document.getElementId("id");

    if(typeof(id) == "undefined" || id == null) {

      console.log("节点不存在");

    else{

      console.log("节点存在");

    }

    注意:typeof(id) == "undefined"  而不是 typeof(id) == undefined

    一般typeof返回的数据类型:

      "undefined"

      "string"

      "boolean"

      "number"

      "object"

      "function"

    1、number

      console.log(typeof(123)); 

      console.log(typeof(NaN));

      console.log(typeof(0));

    2、string

      console.log(typeof('a'));

    3、boolean

      console.log(typeof(true));

      console.log(typeof(false));

    4、undefined

      变量没有对应对象或变量的值为undefined

      console.log(typeof(a));

      var a = undefined;console.log(typeof(a));

    5、object

      var a = {}; console.log(typeof(a));//对象

      var a = []; console.log(typeof(a));//数组

            console.log(typeof(null));

    6、function

      var a = function(){}; console.log(typeof(a));

    //Object.prototype.toString.apply(obj)

  • 相关阅读:
    Attributes in C#
    asp.net C# 时间格式大全
    UVA 10518 How Many Calls?
    UVA 10303 How Many Trees?
    UVA 991 Safe Salutations
    UVA 10862 Connect the Cable Wires
    UVA 10417 Gift Exchanging
    UVA 10229 Modular Fibonacci
    UVA 10079 Pizza Cutting
    UVA 10334 Ray Through Glasses
  • 原文地址:https://www.cnblogs.com/zj68/p/12897730.html
Copyright © 2011-2022 走看看