jQuery.isNumeric()方法

jQuery 杂项方法jQuery 杂项方法

实例

判断输入值类型

$(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任意类型 需要进行判断的任意值。


jQuery 杂项方法jQuery 杂项方法

0 个评论

要回复文章请先登录注册