我創建它使用內置自舉一個HTML頁面的無法設置屬性的「onClick」。這裏是hello.js文件的最終HTML代碼和代碼:遺漏的類型錯誤:空
document.getElementById("subm").onclick=function(){
alert("Hello WOrld");
}
<!DOCTYPE html><html><head><title>Calculator</title><link rel="stylesheet"
href="/stylesheets/style.css"><meta name="viewport" content="width=device-width, initial-
scale=1.0"></head></html><body><link rel="stylesheet" href="/stylesheets/bootstrap.min.css">
<script src="http://code.jquery.com/jquery.js"></script><script
src="javascripts/bootstrap.min.js"></script><script src="javascripts/hello.js"></script>
<h1>Calculator</h1><form class="form-horizontal center1"><div class="control-group"> <label
for="num1" class="control-label">Number1</label><div class="controls"><input id="num1"
type="number" placeholder="Enter an Integer"></div></div><div class="control-group">
<label for="num2" class="control-label">Number2</label><div class="controls"><input
id="num2" type="number" placeholder="Enter an Integer"></div><div class="control-group">
<label for="options" class="control-label">Options</label><div class="controls"><br><select
id="options"><option value="+">+</option><option value="-">-</option><option value="*">*
</option><option value="/">/</option></select></div></div><div class="control-group"><div
class="controls"><br><button id="subm" type="submit" class="btn">Calculate </button></div>
</div><div class="control-group"><div class="controls"><input id="cal" type="text"
placeholder="Calculator output" disabled="true"></div></div></div></form></body>
當我點擊按鈕使用SUBM然後,而不是警告我收到錯誤
Uncaught TypeError: Cannot set property 'onclick' of null
任何人都可以請告訴我爲什麼我面臨這個錯誤?幫助解決它。
腳本在哪裏? –