请教开发chrome扩展插件的脚本事件问题.

图片描述

为什么点击"开启按钮没反应啊?"我在这个按钮上加了click事件
代码:

{
  "manifest_version": 2,

  "name": "hello world",
  "description": ".....",
  "version": "1.0",

  "browser_action": {
      "default_title" : "hello",
   "default_icon": "smile.png",
   "default_popup": "popup.html"
  },
  "permissions": [
   "activeTab"
   ],
  "content_scripts" : [{  
         "matches": ["https://www.google.com/*"],   
         "js": ["js/jquery-1.10.2.min.js","js/test.js"],   
         "run_at": "document_start",  
         "all_frames": true   
    }] 
}

popup.html

<!doctype html>
<html>
  <head>
    <title>hello world</title>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="popup.js"></script>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>Hello</h1>
    <button id="checkPage">开启</button>
  </body>
</html>

popup.js

window.onload = function(){

    document.getElementById("checkPage").onclick = function(){
        alert("44444")
    }
    $("#checkPage").on("click",function(){
        alert("2222")
    })

}

我加了两种事件 点击开启按钮 都没反应..
请问是哪里错了吗?

阅读 4.7k
1 个回答
新手上路,请多包涵

你把外层的window.onload去掉试一试

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题