【发布时间】:2020-08-06 20:11:36
【问题描述】:
我知道我可能遗漏了一些非常简单的东西,但是为什么单击按钮时没有显示警报?与“addEventListener”中的函数有关吗?
谢谢!
const button = document.getElementsByTagName("button");
button.addEventListener("click", function(event){
alert("Heyyyy!")
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>
<button type="button">Click Me!</button>
</p>
<script src=Test.js></script>
</body>
</html>
【问题讨论】:
标签: javascript html button addeventlistener