jQuery.isNumeric()


jQuery.isNumeric( value )返回: 布尔值已弃用版本: 3.3, 已移除: 4.0

描述: 判断其参数是否表示一个 JavaScript 数字。

注意: 此 API 在 jQuery 3.3 中已弃用。

$.isNumeric() 方法检查其参数是否表示一个数值。如果是,则返回 true。否则返回 false。参数可以是任何类型。

从 jQuery 3.0 开始,仅当参数类型为 number,或者当其类型为 string 且可以被强制转换为有限数字时,$.isNumeric() 才返回 true。在所有其他情况下,它返回 false

示例

$.isNumeric 在各种输入下的返回值示例。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// true (numeric)
$.isNumeric( "-10" )
$.isNumeric( "0" )
$.isNumeric( 0xFF )
$.isNumeric( "0xFF" )
$.isNumeric( "8e5" )
$.isNumeric( "3.1415" )
$.isNumeric( +10 )
$.isNumeric( 0144 )
// false (non-numeric)
$.isNumeric( "-0x42" )
$.isNumeric( "7.2acdgs" )
$.isNumeric( "" )
$.isNumeric( {} )
$.isNumeric( NaN )
$.isNumeric( null )
$.isNumeric( true )
$.isNumeric( Infinity )
$.isNumeric( undefined )