Use the "instanceof" operator to determine whether an object is a jquery object; the instanceof operator can determine whether an object is a specified data type. The syntax is "if (object variable instanceof jQuery) {//It is a 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
: Determine whether an object is a certain data type, or whether a variable is an instance of an object; return boolean type
Example :
var obj = $("div"); if(obj instanceof jQuery){ alert("这是一个jQuery对象"); }else{ alert("这是一个其它对象") }
Explanation: Instanceof and typeof can be used to determine whether a variable is empty or what type of variable it is.
typeof: Used to obtain the type of a variable. Typeof generally 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 a!="undefined"){}
instead of using if(a) because if a does not exist (Not declared) will cause an error. Using typeof for special objects such as Array and Null will always return object. This 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 must choose to use instanceof
.
instanceof is used to determine whether a variable is an instance of an object, such as the arguments of
var a=new Array(); alert(a instanceof Array); //会返回true alert(a instanceof Object) //也会返回true;这是因为Array是object的子类 function test(){}; var a=new test(); alert(a instanceof test) //会返回true
function. We all may think that arguments are an Array, but if you use Instaceof tests and finds that arguments is not an Array object, although it looks similar.
Test
var a=new Array(); if (a instanceof Object) alert('Y'); else alert('N'); //Y
But:
if (window instanceof Object) alert('Y'); else alert('N'); //N
So, the object tested by instanceof here refers to the object in js syntax, not the dom model object.
There will be some differences when using typeof
alert(typeof(window) //会得 object
[Recommended learning: jQuery video tutorial, web front-end development]
The above is the detailed content of Determine whether to use what operator for a jquery object. For more information, please follow other related articles on the PHP Chinese website!

在c语言中,没有开根号运算符,开根号使用的是内置函数“sqrt()”,使用语法“sqrt(数值x)”;例如“sqrt(4)”,就是对4进行平方根运算,结果为2。sqrt()是c语言内置的开根号运算函数,其运算结果是函数变量的算术平方根;该函数既不能运算负数值,也不能输出虚数结果。

在Java中,“%”是取余的意思,是一个二元算术运算符,可进行除法运算并获取余数,语法“操作数1 % 操作数2”。取余运算符“%”的操作数通常是正整数也可以是负数甚至是浮点数,如果负数参与此运算,则结果的正负取决于前面一个数是正数还是负数。

对于Golang开发者来说,“invaliduseof…operator”是一个常见的报错。这个报错通常会在使用变长参数函数时出现。它在编译时就会被检测出来,并指出哪些部分有问题。这篇文章将介绍如何解决这个报错。一、什么是变长参数函数变长参数函数也被称为可变参数函数,是Golang语言中的一种函数类型。使用变长参数函数可以像如下方式定义多个

在php中,“==”符号是一个比较运算符,可以比较两个操作数是否相等,语法“操作数1 == 操作数2”。“==”运算符会比较、并测试左边的变量(表达式或常量)是否与右边的变量(表达式或常量)具有相同的值;它只比较变量的值,而不是数据类型。如果两个值相同,则返回true值;如果两个值不相同,则返回false值。

在php中,可以使用“%”和“==”运算符来判断两个数能否整除;只需要使用“%”运算符将两个数相除获取余数,再使用“==”运算符判断获取的余数是否为0即可,语法“数1 % 数2 == 0”,如果为0则能整除,如果不为0则不能整除。

python中的魔法方法是一些可以让你对类添加“魔法”的特殊方法,它们经常是两个下划线包围来命名的。Python的魔法方法,也称为dunder(双下划线)方法。大多数的时候,我们将它们用于简单的事情,例如构造函数(init)、字符串表示(str, repr)或算术运算符(add/mul)。其实还有许多你可能没有听说过的但是却很好用的方法,在这篇文章中,我们将整理这些魔法方法!迭代器的大小我们都知道__len__方法,可以用它在容器类上实现len()函数。但是,如果您想获取实现迭代器的类对象的长度

在Go语言中,运算符按照优先级从高到低的顺序进行计算。常见的运算符的优先级顺序:1、括号:()(最高优先级,用于强制改变运算顺序);2、单目运算符;3、乘性运算符;4、加性运算符;5、移位运算符;6、按位运算符;7、比较运算符;8、逻辑运算符;9、条件运算符(三元运算符);10、赋值运算符等等。

使用按位左移运算符,从右侧移动一个或多个零位。不考虑最左边的位。示例您可以尝试运行以下代码来了解如何使用JavaScript按位左移运算符。<!DOCTYPEhtml><html> <body> <script> document.write("B


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
