目前試圖寫一個腳本,將允許網站的用戶電子郵件地址添加到郵件列表訂閱一份通訊(它在早期階段)爲什麼document.getElementByID引發錯誤?
每次我跑我收到以下錯誤代碼:
Newsletter.js:2 Uncaught TypeError: document.getElementByID is not a function
at Newsletter.js:2
at Newsletter.js:11
據我所知,這是第2和第11行有問題,我只是看不出是什麼問題。
我已經包含了所有相關的HTML和CSS。
任何幫助將不勝感激。
的形式位於頁腳區域,所以我剛纔列入HTML頁腳:
<footer class="container-fluid text-center">
<p id="TestSubmit">Online Store Copyright</p>
<form class="form-inline" id = "NewsletterEmail">Get deals:
<input type="email" class="form-control" size="50"
placeholder="Email Address" id="EmailAddress">
<button type="button" class="btn btn-danger" id="Submit">Sign
Up</button>
</form>
<script src="JS/Utilities.js"></script>
<script src="JS/Newsletter.js"></script>
</footer>
function addEvent(el, event, callback) {
if ('addEventListener' in el) {
el.addEventListener(event, callback, false);
} else {
el['e' + event + callback] = callback;
el[event + callback] = function() {
el['e' + event + callback](window.event);
};
el.attachEvent('on' + event, el [event + callback]);
}
}
(function(){
var form = document.getElementByID('NewsletterEmail');
addEvent(form, 'Submit', function(e){
e.preventDefault();
var elements = this.elements;
var email = elements.email.value;
var msg = 'Welcome ' + username;
document.getElementByID('TestSubmit').textContent = msg;
});
}());
的可能的複製[的document.getElementById不是一個函數(https://stackoverflow.com/questions/6409505/document-getelementbyid-is-not-a-function ) – Durga
選中此項[getElementById](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById)。不'getElementByID' – Durga