我正在嘗試爲Project Euler#1(計算從0到1000的3或5的倍數的數字總和)創建一個簡單的html表單,讓用戶輸入一個數字而不是從0到1000進行計算。我認爲我的結果很接近,但我無法獲得任何值返回到網頁上。無法將數據返回到網頁
<body>
<form action="" id="numform" onsubmit="return false">
<fieldset>
<legend>Lets do Math!</legend>
<label>Enter a number</label>
<input type="text" name="num" id="num">
<button onclick="add">Calculate</button>
<div id="totalSum"></div>
</fieldset>
</form>
</body>
function addThreeAndFive() {
var theForm = document.forms["numform"];
var num = theForm.elements["num"]
var sum = 0;
for (var i = 0; i <= num; i++) {
if (i % 3 === 0 || i % 5 === 0) {
sum += i;
}
}
document.getElementById('totalSum').innerHTML = "The sum of the multiples of 3 and 5 are " + sum;
}
也'fieldset'拼寫錯誤 – foxygen 2014-10-31 00:36:53