JS复习:监测按钮点击事件触发方法(通过选择id)
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/922
JS复习:监测按钮点击事件触发方法。
触发方法有多种,这里只说一个最简单的监听事件的。
你的HTML部分:
<button id="startBtn">开始</button>
<button id="stopBtn">停止</button>
你的JS代码:
document.getElementById('startBtn').addEventListener('click', function() {
//ToDo: Your function.
});
document.getElementById('stopBtn').addEventListener('click', function() {
cancelAnimationFrame(requestId);
//ToDo: Your function.
});
你的方法(注意与document同级):
function whatever() {
//随便写点什么罢
}
其它5种方法:
[4] JS复习:监测按钮点击事件触发方法(通过属性选择器)
[5] JS复习:监测按钮点击事件触发方法(通过后代选择器)
论外:
This article was last edited at 2023-05-10 06:33:31