javascript - 按钮不起作用并更改边框颜色
问题描述
我尝试编写一个小 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";
}
解决方案
只是关于大写的一个小语法问题: write but
, not But
,因为But
是undefined。
推荐阅读
- jquery - 在第一次提交时无法使用 ckeditor 获取 Textarea 表单的值,但它适用于第二次提交
- java - 使用 Java 在现有 json 文件中附加 json 对象
- r - 随机森林模型中移除响应变量的标准
- python - 在 .py 文件之间定义全局变量的正确方法是什么
- python - ImportError:无法导入名称“后端”
- c# - .NET 中奇怪的委托和操作行为
- corda - corda 节点可以成为多个 corda 网络的一部分吗?一个带有多个 NMS 的 corda 节点可能吗?如何实现私有网管?
- javascript - 在一个命令中运行多个 nodejs 服务器
- c# - 在 ApplicationDbContext 类中访问经过身份验证的用户信息 (ASP.NET Core)
- vue.js - 使用 vuex 确保存储状态中存在变量