LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

JavaScript函数:IsNumeric()

admin
2010年12月16日 11:52 本文热度 3067
谁能写一个JavaScript的IsNumeric函数,的作用与VBScript函数IsNumeric一样.
急需,我也来写一下,

请测试情况 "--000 ".
"0.11.3 "

该文章在 2010/12/16 11:52:11 编辑过

全部评论9

admin
2010年12月16日 11:52
<script   language= "JavaScript "> <!--
alert(!isNaN( "--000 "));
alert(!isNaN( "0.11.3 "));
alert(!isNaN( "11.3 "));
//--> </script>

该评论在 2010/12/16 11:55:38 编辑过
admin
2010年12月16日 11:52
在JavaScript里面用isNaN()函数可以判别是否为数字.

该评论在 2010/12/16 11:52:51 编辑过
admin
2010年12月16日 11:53
isNaN 计算一个参数,检查它是否为数值。 核心函数 实现版本 Navigator 2.0: 仅在 Unix上 Navigator 3.0, LiveWire 1.0: 所有平台 语法 isNaN(testValue) 参数 testValue 你想要测试的值。 描述 isNaN 是一个内建的 JavaScript 函数。它并不是与任何对象关联的方法,而仅仅是语言的一部分。 在支持 NaN 的平台上,parseFloat 和 parseInt 函数将在计算并不是数值的值时返回“NaN”。isNaN 在传递过来的参数是“NaN”时返回真,否则返回假。 示例 下面的例子计算 floatValue,确定它是否为数值,以便调用相应的过程: floatValue=parseFloat(toFloat) if (isNaN(floatValue)) { notFloat() } else { isFloat() }

该评论在 2010/12/16 11:53:08 编辑过
admin
2010年12月16日 11:53
楼上及楼上的楼上及楼上的楼上. 说得都不对吧. 当toFloat= "123abc ",他会返回真,我想连小学生都知道 "123abc "不是数字吧. floatValue=parseFloat(toFloat) if (isNaN(floatValue)) { notFloat() } else { isFloat() }

该评论在 2010/12/16 11:53:54 编辑过
admin
2010年12月16日 11:54
对 "123abc " isNaN()是会返回true 你可以在比较一下他们的长度

该评论在 2010/12/16 11:54:15 编辑过
admin
2010年12月16日 11:54
true是指非数字!

该评论在 2010/12/16 11:54:25 编辑过
admin
2010年12月16日 11:54
出自 http://www.crockford.com/javascript/remedial.html function isAlien(a) { return isObject(a) && typeof a.constructor != 'function '; } function isArray(a) { return isObject(a) && a.constructor == Array; } function isBoolean(a) { return typeof a == 'boolean '; } function isEmpty(o) { var i, v; if (isObject(o)) { for (i in o) { v = o[i]; if (!!isUndefined(v) && !!isFunction(v)) { return false; } } } return true; } function isFunction(a) { return typeof a == 'function '; } function isNull(a) { return typeof a == 'object ' && !a; } function isNumber(a) { return typeof a == 'number ' && isFinite(a); } function isObject(a) { return (typeof a == 'object ' && !!a) || isFunction(a); } function isString(a) { return typeof a == 'string '; } function isUndefined(a) { return typeof a == 'undefined '; } String.method( 'entityify ', function () { return this.replace(/&/g, "& ").replace(/ /g, "> "); });

该评论在 2010/12/16 11:54:39 编辑过
admin
2010年12月16日 11:54
function validateForm_Num(charpos) { var number; number = new Number(charpos); if (isNaN(number)) { return false; } else if (number> =0) { return true; } else { return false; } return true; } 如果validateForm_Num(strTemp)==false 则不为数字否则为数字,但对负数无效

该评论在 2010/12/16 11:54:54 编辑过
admin
2010年12月16日 11:55
//整数 function checkInt(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) var elm = (document.all)?(e.srcElement):(e.target) return ( "0123456789 ".indexOf(ch)> -1 || (ch== "- " && (elm.value==null || elm.value== ' '))) } //浮点数 function checkFloat(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) var elm = (document.all)?(e.srcElement):(e.target) return ( "0123456789 ".indexOf(ch)> -1 || (ch== ". " && elm.value.indexOf( ". ")==-1) || (ch== "- " && (elm.value==null || elm.value== ' '))) } //正整数 function checkPositiveInt(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) return ( "0123456789 ".indexOf(ch)> -1) } //正浮点数 function checkPositiveFloat(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) var elm = (document.all)?(e.srcElement):(e.target) return ( "0123456789 ".indexOf(ch)> -1 || (ch== ". " && elm.value.indexOf( ". ")==-1)) } //百分比 80%显示为80 function checkPercent(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) var elm = (document.all)?(e.srcElement):(e.target) return (( "0123456789 ".indexOf(ch)> -1 || (ch== ". " && elm.value.indexOf( ". ")==-1) || (ch== "- " && (elm.value==null || elm.value== ' '))) && ((elm.value+ch)*1.0 <=100 && (elm.value+ch)*1.0> =-100 )) } //百分比 80%显示为0.80 function checkPercentDecimal(e){ var code = (document.all)?(e.keyCode):(e.which) if (code==0 || code==8) return true; var ch=String.fromCharCode(code) var elm = (document.all)?(e.srcElement):(e.target) return (( "0123456789 ".indexOf(ch)> -1 || (ch== ". " && elm.value.indexOf( ". ")==-1) || (ch== "- " && (elm.value==null || elm.value== ' '))) && ((elm.value+ch)*1.0 <=1 && (elm.value+ch)*1.0> =-1)) }

该评论在 2010/12/16 11:55:09 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved