找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 查看内容

jquery如何判断是否是其对象

作者:模板之家 2020-12-21 13:56 75人关注

jquery判断是否是其对象的方法:判断一个对象是否为jquery对象可以用obj instanceof jQuery,代码为【if(obj instanceof jQuery){alert(这是一个jQuery对象);}】。

jquery判断是否是其对象的方法:判断一个对象是否为jquery对象可以用obj instanceof jQuery,代码为【if(obj instanceof jQuery){alert("这是一个jQuery对象");}】。

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

推荐: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(视频)

以上就是jquery如何判断是否是其对象的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: 网络收集

全部回复(0)