如何判斷一個物件是否為jquery物件
阿新 • • 發佈:2018-11-14
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
當我們在用jquery的each做迴圈遍歷的時候常常會使用到this
而有時候我們不知道this所指的到底是什麼,因為要使用jquery
的方法 前提此物件必須是jquery物件。另外要判斷一個javascript的物件是什麼型別,可以使用typeof,
判斷一個物件是否為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 })