JQuery实现动态加载的多个相同class元素的点击事件

Posted Rose✿留白ق೨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JQuery实现动态加载的多个相同class元素的点击事件相关的知识,希望对你有一定的参考价值。

话不多说,请直接复制下面这段代码到html页面,然后用浏览器打开。

<input type="button" value="删除" class="delBtn" id="1"/>
<input type="button" value="删除" class="delBtn" id="2"/>
<input type="button" value="删除" class="delBtn" id="3"/>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
	$(".delBtn").on("click",function()
		alert(this.id);
	)
</script>

方法:

把
$(".delBtn").click(function())
修改为
$(".delBtn").on("click",function()

以上是关于JQuery实现动态加载的多个相同class元素的点击事件的主要内容,如果未能解决你的问题,请参考以下文章