Chrome扩展程序-未捕获的ReferenceError:未定义元素

时间:2018-08-25 23:37:17

标签: javascript google-chrome-extension

我正在尝试制作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

0 个答案:

没有答案