当前代码有效,当单击按钮时将发出警报,但是如果我将myAlert
移到另一个文件中并导入它,它将停止工作。任何人都知道发生了什么事吗?
manifest.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;