您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年09月24日 12:56

原创 jQuery.isNumeric() 函数详解

3985 次浏览 读完需要≈ 4 分钟

内容目录

jQuery.isNumeric()函数用于判断指定参数是否是一个数字值

该函数属于全局jQuery对象。

语法

jQuery 1.7 新增静态函数

jQuery.isNumeric( value )

参数

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

返回值

jQuery.isNumeric()函数的返回值为Boolean类型,如果指定的参数是一个数字值,则返回true,否则返回false

字符串形式的数字也符合条件。

示例&说明

jQuery.isNumeric()函数的jQuery示例代码如下:

//在当前页面内追加换行标签和指定的HTML内容
function w( html ){
	document.body.innerHTML += "<br/>" + html;
}



w( $.isNumeric( 12 ) ); // true
w( $.isNumeric( 12.35 ) ); // true
w( $.isNumeric( "12" ) ); // true
w( $.isNumeric( "12.34" ) ); // true
// 十六进制
w( $.isNumeric( "0x123" ) ); // true
w( $.isNumeric( new Number( 12 ) ) ); // true

w( $.isNumeric( null ) ); // false
w( $.isNumeric( true ) ); // false
w( $.isNumeric( "CodePlayer" ) ); // false
w( $.isNumeric( { } ) ); // false
w( $.isNumeric( [ 0 ] ) ); // false
w( $.isNumeric( NaN ) ); // false

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单