怎么判断对象是否为jquery对象

2023-12-25 04:38:24
推荐回答(1个)
回答1:

判断一个对象是否为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
})