這裏是我想達到的,但出於某種原因,這是行不通的:訪問HTML表單值的JavaScript
的Javascript:
<script type="text/javascript">
function calculate() {
var n1 = getElementById("1").value
var n2 = getElementById("2").value
var answer = n1+n2
alert(answer)
}
</script>
HTML:
<form id="form">
<input id="1" type="text" />
<input id="2" type="text" />
<input type="button onClick="calculate()" value="Go" />
</form>
我不知道我錯了哪裏,有人可以幫忙嗎?
我從來不知道這一點,非常感謝 – 2013-04-20 18:42:17
@ user125697有趣的是,現在在HTML5中允許用數字開始ID;但是,這裏的ID在CSS和HTML5中仍然是非法的 - 因爲HTML5在ID中需要「至少一個字符」:http://www.w3.org/html/wg/drafts/html/master/dom.html #the-id-attribute – 2013-04-20 19:25:02
@SamCreamer嘿!隨時接受我的答案,如果它有幫助(檢查這個如何做--http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),非常感謝! – lifetimes 2013-05-25 00:41:33