【发布时间】:2017-04-28 15:32:48
【问题描述】:
我有这个功能:
function validar(e) {
var xx = 1;
tecla = (document.all) ? e.keyCode : e.which; // 2
if (tecla == 8) return true; // 3
patron = /[A-Za-z\s]/; // 4
te = String.fromCharCode(tecla); // 5
var valorNumerico = Number(te);
if (te > 1 && te < 11) {
alert('Calificación:' + valorNumerico)
} else {
alert('La Calificación debe estar entre 2 y 10 - ' + valorNumerico)
}
}
其目标是捕获用户的输入并验证范围为 2 到 10
但是,告诉我NaN
我试过valorNumerico = parseInt(te);
给我看NaN
我试过valorNumerico = Integer.parseInt(te);
给我看NaN
那么,我怎样才能转换成整数呢?谢谢我在 javascript 中使用了一个函数到 asp.net
【问题讨论】:
-
你如何声明
te?tecla是什么? -
te的值是多少?并非每个字符串值都可以转换为数字。您在这里的最终目标是什么? -
好像te不包含数字
-
函数验证器(e) { var xx = 1; tecla = (document.all) ? e.keyCode : e.which; // 2 if (tecla == 8) return true; // 3 位赞助人 = /[A-Za-z\s]/; // 4 te = String.fromCharCode(tecla); // 5 var valorNumeric = Number(te); if (te > 1 && te
-
@David Ortega 更新您的问题,不要添加评论。
标签: javascript string integer