JS复习:监测按钮点击事件触发方法(通过选择标签)
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/928
JS复习:监测按钮点击事件触发方法(通过选择标签)
HTML部分:
<button>点击我</button>
JavaScript部分:
var buttons = document.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function() {
alert("Hello World!");
});
}
其它5种方法:
[4] JS复习:监测按钮点击事件触发方法(通过属性选择器)
[5] JS复习:监测按钮点击事件触发方法(通过后代选择器)
论外:
This article was last edited at 2023-05-10 06:38:06