本文摘自PHP中文网,作者藏色散人,侵删。
jquery判断是否为数字的方法:首先创建一个前端代码示例文件;然后通过“if(!isNaN(t)){...}”方法判断是否为数字;最后输出判断结果即可。
本教程操作环境:Windows7系统、jquery1.10.0版,该方法适用于所有品牌电脑。
推荐:《jquery教程》
jQuery 判断是否为数字的方法 及 转换数字函数
1 2 3 4 5 6 7 8 | <script language= "javascript" >
var t=$( "#id" ).val();
if (!isNaN(t)){
alert( "是数字" );
} else {
alert( "不全是数字" );
}
</script>
|
附:
JavaScript Number() 函数
Number() 函数把对象的值转换为数字。
1 2 3 4 5 6 7 8 9 10 11 12 | <script type= "text/javascript" >
var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date ();
var test4= new String( "999" );
var test5= new String( "999 888" );
document.write(Number(test1)+ "<br />" );
document.write(Number(test2)+ "<br />" );
document.write(Number(test3)+ "<br />" );
document.write(Number(test4)+ "<br />" );
document.write(Number(test5)+ "<br />" );
</script>
|
输出
更多编程相关知识,请访问:编程学习!!
以上就是jquery判断是否为数字的方法的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
jQuery miniui是什么?
jQuery中怎么获取文本框的值
jQuery ligerui是什么?
jQuery如何判断是否为空
jQuery如何判断文件是否存在
详解jQuery的扩展方法extend
jQuery on()怎么用
浅谈jQuery中的each方法
jQuery怎样判断鼠标是否在div上
jQuery中bind与on的区别是什么
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jquery判断是否为数字的方法