我是JavaScript新手,我試圖弄清楚如何將用戶輸入值作爲參數傳遞給JavaScript函數。以下是我的代碼:將HTML輸入值作爲JavaScript函數參數傳遞
<body>
<h1>Adding 'a' and 'b'</h1>
<form>
a: <input type="number" name="a" id="a"><br>
b: <input type="number" name="b" id="a"><br>
<button onclick="add(a,b)">Add</button>
</form>
<script>
function add(a,b) {
var sum = a + b;
alert(sum);
}
</script>
</body>
[Javascript獲取輸入文本值]的可能重複(http://stackoverflow.com/questions/11563638/javascript-get-input-text-value) –