Home > Web Front-end > JS Tutorial > What is the method for jquery to determine whether it is a number?

What is the method for jquery to determine whether it is a number?

王林
Release: 2020-11-30 14:06:47
Original
2726 people have browsed it

How jquery determines whether it is a number: You can use the isNumeric method to determine, such as [$.isNumeric(0xFF);]. When using this method for judgment, some special characters will be treated as octal or hexadecimal numbers.

What is the method for jquery to determine whether it is a number?

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

(Learning video sharing: javascript video tutorial)

1.$.isNumeric();

The built-in one in jquery is used to determine whether is a function of numbers. If you use $.isNumeric() to determine whether it is a number, some special characters will be treated as octal or hexadecimal numbers and will be judged as true.

$.isNumeric(0xFF);    //true
$.isNumeric("0xFF");    //true
Copy after login

2. isNaN();

A function in js used to determine whether it is a number. It means "not a number", that is, "determine whether it is not a number". If it is not a number, it will be true, if it is a number, it will be false." Its disadvantage is that some variables with empty values, such as null, spaces, etc., will convert them to "0" and treat them as numbers:

isNaN("abc");//true
isNaN(null);//false
Copy after login

3. Number();

The Number() function is actually used in js to convert a string into a number, but it can also be used by us to determine whether it is a number. If it is not a number, the value "NaN" will be returned, but like isNaN() above, if the value is null or empty, a 0 will be returned:

Number("aijquery.cn");//NaN
Number(null);//0
Copy after login

Related recommendations: js tutorial

The above is the detailed content of What is the method for jquery to determine whether it is a number?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template