有人可以请告知为什么下面的函数中的'inputValue'变量没有被转换为数字。我期待第二个console.log
报告该变量现在是一个数字(因为我申请parseInt
它)。 但显然它仍然是一个字符串。将字符串转换为JS中的数字
function checkIfNum(){
var inputValue = document.getElementsByTagName('input')[0].value;
console.log(inputValue);
// Convert to a number
parseInt(inputValue);
console.log(typeof(inputValue));
}
感谢RGraham - 有一天我会得到一个程序员的大脑。 – swisstony
@swisstony嘿,我们都会犯错!其他人更容易看到代码中的问题,而不是看到你自己的:) – CodingIntrigue