按钮 onclick 在网页中使用时有效,但在 chrome 扩展中无效

问题描述

所以我开始制作一个 chrome 扩展,但很快就遇到了一个问题,当我按下一个按钮(只有 popup.html 文件中的元素)时,它没有运行它应该运行的脚本,而当我将 html 文件作为网页运行。

<!DOCTYPE html>
<html>
  <head>
    <script>
      function mainbuttonpressed() {
        document.getElementById("mainbutton").innerHTML = "B"
        console.log("pressed1")
        alert("You pressed the button!")
        console.log("pressed2")
      }
    </script>
    <link rel="stylesheet" href="button.css">
  </head>
  <body>
    <button id="mainbutton" type="button" onclick="mainbuttonpressed()">A</button>
  </body>
</html>


当我将其用作网页时,它是如何工作的,但在 chrome 扩展程序中用作 default_popup 时完全相同的 html 没有反应是怎么回事?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)