Latest web development tutorials

jQuery.isNumeric() 方法

jQuery 雜項方法 jQuery雜項方法

實例

判斷輸入值類型

$ ( function ( ) { function fun ( html ) { document . body . innerHTML += " <br> " + html ; } // true fun ( $. isNumeric ( " -10 " ) ) ; fun ( $. isNumeric ( " 0 " ) ) ; fun ( $. isNumeric ( 0x FF ) ) ; fun ( $. isNumeric ( " 0xFF " ) ) ; fun ( $. isNumeric ( " 8e5 " ) ) ; fun ( $. isNumeric ( " 3.1415 " ) ) ; fun ( $. isNumeric ( + 10 ) ) ; fun ( $. isNumeric ( 0144 ) ) ; // false fun ( $. isNumeric ( " -0x42 " ) ) ; fun ( $. isNumeric ( " 7.2acdgs " ) ) ; fun ( $. isNumeric ( " " ) ) ; fun ( $. isNumeric ( { } ) ) ; fun ( $. isNumeric ( NaN ) ) ; fun ( $. isNumeric ( null ) ) ; fun ( $. isNumeric ( true ) ) ; fun ( $. isNumeric ( Infinity ) ) ; fun ( $. isNumeric ( undefined ) ) ; } )

嘗試一下»

定義和用法

$.isNumeric() 函數用於判斷指定參數是否是一個數字值。

注意:在jQuery 3.0中,$.isNumeric()方法只有接收number類型的參數,或者是可以被強制為有限數值的string類型的參數時,才會返回true,否則返回false。


語法

$.isNumeric( value )

参数 描述
value 任意类型 需要进行判断的任意值。


jQuery 雜項方法 jQuery雜項方法