In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to judge whether it is an jquery object. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
Use the "instanceof" operator to determine whether an object is a jquery object; the instanceof operator can determine whether an object is of a specified data type, with the syntax "if (object variable instanceof jQuery) {/ / is jQ object} else {/ / not}".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Use the "instanceof" operator to determine whether an object is a jquery object.
Instanceof: determines whether an object is a data type or whether a variable is an instance of an object; returns the boolean type
Example:
Var obj = $("div"); if (obj instanceof jQuery) {alert ("this is a jQuery object");} else {alert ("this is another object")}
Description: both instanceof and typeof can be used to determine whether a variable is empty or what type of variable it is.
Typeof: used to get the type of a variable. Generally, typeof can only return the following results: number, boolean, string, function, object, undefined.
We can use typeof to get whether a variable exists, such as if (typeof aversion = "undefined") {}, instead of using if (a) because if a does not exist (undeclared), it will make an error. Using typeof for special objects such as Array, Null, etc., all returns object, which is the limitation of typeof.
If we want to get whether an object is an array or determine whether a variable is an instance of an object, we choose to use instanceof.
Instanceof is used to determine whether a variable is an instance of an object, such as
Var a=new Array (); alert (an instanceof Array); / / returns truealert (an instanceof Object) / / also returns true; because Array is a subclass of object function test () {}; var a=new test (); alert (an instanceof test) / / returns true
Function's arguments, we may all think that arguments is an Array, but if you use instaceof to test, you will find that arguments is not an Array object, although it looks like it.
test
Var a=new Array (); if (an instanceof Object) alert ('Y'); else alert ('N'); / / Y
But:
If (window instanceof Object) alert ('Y'); else alert ('N'); / / N
So, the object of the instanceof test here refers to the object in the js syntax, not the dom model object.
There are some differences in using typeof
Alert (typeof (window) / / will get object above is all the content of this article "how to judge whether it is a jquery object or not". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.