JS复习:监测按钮点击事件触发方法(通过后代选择器)
2023-05-10 15:05:02 JST |
Web Design |
1k+ Reads
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/930
JS复习:监测按钮点击事件触发方法(通过后代选择器)
这个你也不一定常用。但是还是需要记忆。
HTML部分:
<div id="myDiv">
<button>点击我</button>
</div>
JavaScript部分:
var myDiv = document.getElementById("myDiv");
var button = myDiv.querySelector("button");
button.addEventListener("click", function() {
alert("Hello World!");
});
其它5种方法:
[1] JS复习:最简单的通过点击触发方法
[2] JS复习:监测按钮点击事件触发方法(通过选择id)
[3] JS复习:监测按钮点击事件触发方法(通过选择类)
[4] JS复习:监测按钮点击事件触发方法(通过选择标签)
[5] JS复习:监测按钮点击事件触发方法(通过属性选择器)
论外:
JS复习:通过表单提交触发方法
JS复习:伪类选择器
返回:[目录] JavaScript基础:方法触发相关
This article was last edited at 2023-05-10 15:38:39 JST
Related Articles
Website Rebuild & Patch Notes
After months of planning and development, I'm excited to share the fully rebuilt version of my website. This update marks a major shift in both design and architecture — moving away from the legacy ASP.NET Core 2.1 MVC framework to a modern .NET 8 Blazor Web App, combining both Blazor Server and WebAssembly. In this post, I’ll highlight the
2025-03-24 15:32:25 JST
|
Web Design
|
116 reads 在a标签里面增加rel="noopener noreferrer"有什么用?
简单来讲,这样做是为了防止钓鱼网站。你的页面如果不加上这个rel="noopener"会被人链接到别的网站,原理:
2020-01-22 08:03:25 JST
|
Web Design
|
3k reads How to do blog donation function?
About CSS: The total number of images replaced is 3, which are quotation marks, radio1 and radio2 images The. Content class may conflict with your CSS. It is necessary to modify your style About JavaScript: No change required
2020-07-03 00:57:07 JST
|
Web Design
|
2k reads 博客打赏功能制作(附源码)及详细说明
关于CSS: 图片替换总数为3张,分别为引号、radio1、radio2图片 .content类可能与你的CSS冲突,有必要修改你的样式 关于JavaScript: 无需改动 关于HTML: alipay.jpg\wechat.jpg\alipayimg.png\wechatimg.png\close.jpg 要准备好 注意裁剪二维码,大小为140*140px
2020-06-13 18:23:18 JST
|
Web Design
|
2k reads Why not recommend you to use Blogger in 2020 (Specially for programmers)
As a programmer, I recommend that you write a blog yourself instead of using blogger. A few days ago, I used Blogger and I found its editor very difficult to use. Because I am a programmer, I need to paste the code, but the display of the code in Blogger is very bad. For example, the style I thought would work, but it didn't work on Blogger. I think the CSS style has been overwritten. So I opened
2020-12-14 16:46:06 JST
|
Web Design
|
2k reads 仿CSDN侧边栏滚轮响应脚本
这是本网站使用的,仿CSDN侧边栏滚轮响应脚本,需要先引入Jquery配合使用
2020-01-24 22:01:37 JST
|
Web Design
|
1k reads