【问题标题】:getElementById not working in popup.js [chrome extension]getElementById 在 popup.js [chrome 扩展名] 中不起作用
【发布时间】:2018-05-17 17:06:39
【问题描述】:

我想在我的 chrome 扩展弹出窗口中将单词 null 替换为单词 REPLACED

我的 HTML

<!DOCTYPE html>

<html>
  <head>
    <script src="popup.js" type="text/javascript"></script>
  </head>

  <body>
    <h1> Wordnik Lookup </h1>
    <p id = "userselect">null</p>

  </body>
</html>

我的 popup.js:

document.getElementyById("userselect").innerHTML = "REPLACED!";

我从检查弹出窗口中得到的错误消息

未捕获的类型错误:document.getElementyById 不是函数

对此的任何帮助将不胜感激:)

【问题讨论】:

  • 你有 getElementyById(t 和 B 之间的额外 y)而不是 getElementById

标签: javascript google-chrome


【解决方案1】:

有两种错误。一个是typo(拼写错误)。另一个是包含JavaScript的位置。

<html>
  <head>

  </head>

  <body>
    <h1> Wordnik Lookup </h1>
    <p id = "userselect">null</p>

     <!--- Kep JavaScript at end. Otherwise listen for DOMContentloaded event --->
     <script src="popup.js" type="text/javascript"></script>
  </body>
</html>

popup.js内部

document.getElementById("userselect").innerHTML = "REPLACED!";

【讨论】:

  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多