jQuery.isNumeric()方法
實例
判斷輸入值類型
$(function () {
function fun( html ){
document.body.innerHTML += "<br>" + html;
}
// true
fun($.isNumeric( "-10" ));
fun($.isNumeric( "0" ));
fun($.isNumeric( 0xFF ));
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 | 任意類型 需要進行判斷的任意值。 |