相关疑难解决方法(0)

Chrome浏览器中的onClick无效

这似乎是最简单的事情,但它只是不起作用.在普通的浏览器中,.html和.js文件工作正常,但在Chrome扩展程序中,该onClick功能没有执行它应该执行的操作.

.js文件:

function hellYeah(text) {
  document.getElementById("text-holder").innerHTML = text;
}
Run Code Online (Sandbox Code Playgroud)

.html文件:

<!doctype html>
<html>
  <head>
    <title>
      Getting Started Extension's Popup
    </title>
    <script src="popup.js"></script>
  </head>
  <body>
    <div id="text-holder">
      ha
    </div>
    <br />
    <a onClick=hellYeah("xxx")>
      hyhy
    </a>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

所以基本上一旦用户点击"hyhy","ha"应该变成"xxx".再次 - 它在浏览器中完美运行,但在扩展中不起作用.你知道为什么吗?以防我在下面附上manifest.json.

提前致谢!

manifest.json的:

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "http://api.flickr.com/"
  ]
}
Run Code Online (Sandbox Code Playgroud)

javascript onclick google-chrome-extension

60
推荐指数
2
解决办法
9万
查看次数