首页 > 解决方案 > 按钮不起作用并更改边框颜色

问题描述

我尝试编写一个小 Firefox 扩展程序,但我没有让弹出窗口中的 Button 正常工作。单击按钮时应该发生的情况是红色边框变为绿色边框。我找不到错误。

这是我的 manifest.json

{

  "manifest_version": 2,
  "name": "Testing",
  "version": "1.0",

  "description": "Testing",

  "icons": {
    "48": "icon.jpg"
  },

  "content_scripts": [
    {
      "matches": ["*://*.allee-abi20.de/*"],
      "js": ["ust.js"]
    }
  ],
    
  "permissions": [
    "activeTab",
    "contextMenus"
  ],
  
  "browser_action": {
        "default_icon": "icon.jpg",
        "default title": "Hallo",
        "default_popup": "view.html"
    }
}

这就是view.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <link rel="stylesheet" href = "style.css" type="text/css"/> 
    </head>
    <body>
        <input type=text id="Kat"></input>
        <input type=text id="Ty"></input>
        <button id= "but">Klicken </button>     
    <script type="text/javascript" src="./popup.js"></script>   
    </body>
</html>

这就是popup.js

document.body.style.border = "5px solid red";
var myLink = document.getElementById("But");
myLink.onclick = function(){
    document.body.style.border = "20px solid green";
}

标签: javascriptfirefox-addon

解决方案


只是关于大写的一个小语法问题: write but, not But,因为Butundefined


推荐阅读