判断一个对象是否为jquery对象的方法
更新时间:2014年03月12日 15:15:23 作者:
在用jquery的each做循环遍历的时候常常会使用到this,要使用jquery的方法 前提此对象必须是jquery对象,下面为大家介绍下jquery对象的判断方法
当我们在用jquery的each做循环遍历的时候常常会使用到this,而有时候我们不知道this所指的到底是什么,因为要使用jquery的方法 前提此对象必须是jquery对象。
另外要判断一个javascript的对象是什么类型,可以使用typeof,
但是typeof只能判断出js的基础对象(string,boolean,number,object)
判断一个对象是否为jquery对象可以用 obj instanceof jQuery
例如:
var obj = $("div");
if(obj instanceof jQuery){
alert("这是一个jQuery对象");
}else{
alert("这是一个其它对象")
}
$(".otherWeek").each(function(){
console.info(this instanceof jQuery); //false
console.info($(this) instanceof jQuery); //true
})
另外要判断一个javascript的对象是什么类型,可以使用typeof,
但是typeof只能判断出js的基础对象(string,boolean,number,object)
判断一个对象是否为jquery对象可以用 obj instanceof jQuery
例如:
复制代码 代码如下:
var obj = $("div");
if(obj instanceof jQuery){
alert("这是一个jQuery对象");
}else{
alert("这是一个其它对象")
}
复制代码 代码如下:
$(".otherWeek").each(function(){
console.info(this instanceof jQuery); //false
console.info($(this) instanceof jQuery); //true
})
相关文章
全面解析jQuery中的$(window)与$(document)的用法区别
这篇文章主要介绍了jQuery中的$(window)与$(document)的用法区别,具体内容大家可查看下文的详细讲解,感兴趣的小伙伴们可以参考一下。2017-08-08
基于Bootstrap和jQuery构建前端分页工具实例代码
本文给大家介绍基于Bootstrap和jQuery构建前端分页工具实例代码,包括前端分页的优缺点和解决办法,对jquery bootstrap分页知识感兴趣的朋友一起通过本文学习吧2016-11-11


最新评论