微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决按钮 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 举报,一经查实,本站将立刻删除。