0
當它運行它只是不會返回一個值,我不明白爲什麼。當我在html文件中運行它時,它似乎工作正常。我的HTML表單不會返回數組中的值嗎?
此外,當數字爲5例如(數字+數字)已返回55而不是10.我認爲這是因爲我有引號,但我一次又一次地檢查,事實並非如此。
幫助非常感謝
HTML
<body>
<form id = 'table' name = 'table'>
<p> Gimme a number </p>
<input id = 'textbox' type = 'number' name = 'inputBox'>
<input id = 'button' type = 'button' value = 'Submit' onclick = 'check()'>
</form>
</body>
的Javascript
function check(){
var number = document.table.inputBox.value;
var array = [number];
array.push(number+number);
alert(array);
https://jsfiddle.net/67tt6te7/
讀取的字符串,解析它作爲一個整數:'var number = parseInt(document.table.inputBox.value,10);' –
你的小提琴不工作,因爲你的小提琴設置錯誤。 JavaScript不在全局範圍內。點擊齒輪圖標並將負載類型更改爲正文或正文。 – epascarello