javascript - 添加导入后,我的 chrome 扩展程序立即停止工作
问题描述
当前代码有效,并会在单击按钮时发出警报,但如果我移动myAlert
到不同的文件并导入它,它将停止工作。有人知道发生了什么吗?
清单.json
{
"name": "Getting Started Example",
"version": "1.0",
"description": "Build an Extension!",
"browser_action": {
"default_popup": "popup.html"
},
"manifest_version": 2
}
popup.html
<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>
<body>
<button id="changeColor"></button>
<script type="module" src="popup.js"></script>
</body>
</html>
popup.js
// import { myAlert } from "./alert";
function myAlert() {
alert("hello");
}
let changeColor = document.getElementById('changeColor');
changeColor.onclick = myAlert;
解决方案
推荐阅读
- javascript - 如何在js中正确使用firebase,而不向用户公开数据库?
- node.js - 反应应用程序集代理不适用于 docker compose
- excel - 如何在当前单元格位置之前添加列中的所有单元格*在另一张表中*?
- ubuntu - 棘手的活动记录搜索。在凌晨 3 点到开始时间之间创建的记录
- unique - 根据条件查找唯一值
- javascript - React中如何设置全屏粒子-bg
- python - AttributeError:“Figure”对象没有“show”属性
- python-3.x - numpy 数据听起来与原始 sound_file.wav 文件不同
- python - 大型数据集的 X 轴不可见
- python - 如何创建与 Web 服务器通信的应用程序(例如 .apk 或 .exe)