所以我一直试图在我的表单中按下一个按钮来调用一个函数,当它被按下时...问题是它向我报告错误说"未捕获的TypeError:undefined不是函数".
下面是我正在使用的代码......
<script>
function lookup() {
document.getElementByID("isbn").value = "FooBar";
}
</script>
<form>
<label for="isbn">ISBN</label>
<input id="isbn" type="text" name="isbn" placeholder="Enter the ISBN...">
<button type="Button" id="findButton" onclick="lookup()" >Find</button>
</form>
Run Code Online (Sandbox Code Playgroud)
应该是getElementById代替getElementByIDSo
只是改变:
document.getElementByID("isbn").value = "TESTING A FUNCTION!";
Run Code Online (Sandbox Code Playgroud)
至
document.getElementById("isbn").value = "TESTING A FUNCTION!";
---------------------^^-------------
Run Code Online (Sandbox Code Playgroud)
由于javascript是区分大小写的,尤其是函数: