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复习:监测按钮点击事件触发方法(通过后代选择器)
论外:
Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).
There is 19h03m33s left until you can comment.