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
最新文章
- 12/13 Oracle连接报错
- jQuery简洁大方的登录页面模板
- 《玩转D语言系列》二、D语言现状、基本规定和相关资源介绍
- jdk1.8下载安装
- Android UI设计中一些不错的示例及第三方控件
- SqlServer 不是主键 如何自增
- 使用chrome联调不在同一个域的请求
- Android 使WebView支持HTML5 Video(全屏)播放的方法
- Python 时间 日期常见操作
- 一些比较好的shellscript脚本
- free命令
- WebClient外部请求乱码
- Maven详解 之 聚合与继承
- 对于利用ica进行fmri激活区识别的理解
- web_api vs2015 新加标题无法打开
- hadoop学习之hadoop完全分布式集群安装
- 在nagios中使用python脚本监控linux主机
- 从大数据技术变迁猜一猜AI人工智能的发展
- 【python】给正则匹配部分命名
- Python自动化编程-树莓派GPIO编程(二)