zoukankan      html  css  js  c++  java
  • javascript 总结(持续更新)

    1.jQuery对象转DOM对象。

       jQuery对象转DOM对象有两种方法,[index]和get(index)。

    var $cr = $("#cr"); //jQuery对象
    var cr1 = $cr[0];      //DOM对象
    var cr2 = $cr.get(0);//DOM对象

    2.DOM对象转jQuery对象。

       用$()把jQuery对象包装起来即可。

    var cr = document.getElementById("cr"); //DOM对象
    var $cr = $(cr); //jQuery对象

    3.null,undefined的区别。

       undefined类型只是一个值,即特殊的undefined。在使用var声明变量但未对其加以初始化时,这个变量的值就是undefined。

       null类型也是只有一个值的数据类型,这个特殊的值是null。从逻辑学的角度看,null值表示一个空对象指针,用typeof操作符检测null会返回"object"。

       上面是定义,区别如下:

      - null是关键字;undefined是Global对象的一个属性
      - null是对象(空对象, 没有任何属性和方法);undefined是undefined类型的值。试试下面的代码:
           document.writeln(typeof null); //return object
           document.writeln(typeof undefined); //return undefined

      - 对象模型中,所有的对象都是Object或其子类的实例,但null对象例外:
           document.writeln(null instanceof Object); //return false


      - null“等值(==)”于undefined,但不“全等值(===)”于undefined:
           document.writeln(null == undefined); //return true
           document.writeln(null === undefined); //return false

      - 运算时null与undefined都可以被类型转换为false,但不等值于false:
           document.writeln(!null, !undefined); //return true,true
           document.writeln(null==false); //return false
           document.writeln(undefined==false); //return false

  • 相关阅读:
    [Outlook] Outlook2013能收但无法发送邮件-0x800CCC13, 0x800CCC0B, 0x8004210B
    [Mobile] 手机浏览器输入框-数字输入框
    [Qcon] 百姓网开发总结
    [QCon] Scrum阅读随想
    [Spring] 事务级别定义
    [Monitor] 监控规则定义
    [Spring Batch] 图解Spring Batch原理
    [JavaCore] 微信手机浏览器版本判断
    Python 编码简单说
    矩阵或多维数组两种常用实现方法
  • 原文地址:https://www.cnblogs.com/zhutianpeng/p/4219872.html
Copyright © 2011-2022 走看看