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