這裏是我正在努力的代碼。我想將這兩個輸入連接在一起,並將結果保存爲一個整數(JS中的數字)。JavaScript - 連接兩個數字並將結果視爲數字
var secsVal = -1;
function valueAssign(i) {
if (secsVal == -1){
document.getElementById("countdown").value = i;
document.getElementById("countdown").innerHTML = (i);
secsVal = i;
}
else {
secsVal = "" + secsVal + i;//concatenating first value of i to the second.
secsVal = secsVal.map(Number);//trying to convert back to num, but I think map() needs to see an array, which I don't think I got here.
document.getElementById("countdown").value = secsVal;
document.getElementById("countdown").innerHTML = (secsVal);//I want to replace the first displayed digit here, with the new (concatenated) number.
}
}
不知道我理解你的要求。在HTML中,您可以存儲的是文本(不是數字或日期等JavaScript數據類型)。 –
有沒有必要轉換回數字。 –
你的意思是像數字(1 +''+'2')'? –