这是我输入的代码,用于查找在名为“txt”的文本框中输入的数字的反向,并且表单名称为“calc2”。我无法弄清楚问题所在。
function rev() {
var n, rn, r;
n = parseInt(calc2.txt.value);
rn = 0;
while(n!==0) {
rn = rn * 10;
rn = rn + r % 10;
n = n / 10;
}
calc2.ans.value = rn;
}
Chrome会显示以下警告:
calc2.js:62 The specified value "NaN" is not a valid number.
The value must match to the following regular expression:
-?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?rev
@ calc2.js:62onclick
@ home.html?txt=511:54
答案 0 :(得分:0)
做这样的事情
function rev() {
var n, rn;
n = parseInt(calc2.txt.value);
rn = 0;
while(n!==0) {
rn = rn * 10;
rn = parseInt(rn + n % 10, 10);
n = parseInt(n / 10, 10);
}
calc2.ans.value = rn;
}