由於某些原因,我試圖更改提交按鈕的功能。我在將數據從HTML標記複製到JS時遇到問題。由以下代碼生成的警報打印「未定義」而不是標籤內的數據。無法將HTML標記的數據複製到JavaScript
<html>
<body>
<input class="inputtext" id="email" name="email" type="text"></div>
<input value="Submit" name="v4l" id="login" class="inputsubmit" type="button" onclick="myFunction();return false">
<script>
function myFunction() {
var TestVar =document.getElementsByClassName('login').value;
alert(TestVar);
}
</script>
</body>
</html>
我知道這可以通過窗體完成,但我需要這種方式。
你的意思'getElementsByClassName方法( 「登錄」)[0] .value'? – soktinpk 2014-09-06 16:32:39
甚至是'getElementById(「login」).value'? (在你的情況下,'登錄'是輸入的ID) – soktinpk 2014-09-06 16:33:29
可能的重複[爲什麼getElementsByClassName不適合我?它返回什麼?](http://stackoverflow.com/questions/10693845/why-getelementsbyclassname-does-not-work-for-me-what-does-it-return) – 2014-09-06 16:34:42