我正在尝试制作Google Chrome扩展程序并通过单击按钮来调用函数。
HTML
<body>
<form method="post">
<input type="text" class="textbox" placeholder="Search" id="inputText">
<button type="submit" class="button" id="submitButton"></button>
</form>
<script type="text/javascript" src=script.js></script>
</body>
script.js
submitButton = document.getElementById("submitButton")
if (submitButton) {
document.addEventListener('DOMContentLoaded', function() {
submitButton.addEventListener("click", submit);
});
}
...
function submit() {
...
}
输出
Uncaught ReferenceError: submitButton is not defined