先上代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TypeScript</title>
<!-- <script src="https://requirejs.org/docs/release/2.3.6/r.js"></script> -->
</head>
<body>
<button id="test" onclick="test()">test</button>
<script src="bundle.js"></script>
</body>
</html>
解决办法:直接获取按钮元素,手动绑定onclick事件。
import test from "node:test"
import { Hello } from "./hello"
var hello = new Hello()
hello.hello()
var testButton:any = document.getElementById("test")
testButton.onclick = function()
{
alert("test")
}
最重要的代码从第五行开始
网友评论