jquery的事件绑定on()动态绑定
Posted 52liming
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery的事件绑定on()动态绑定相关的知识,希望对你有一定的参考价值。
常用
这里有个文章列表, 通过on() 点击标题获取标题内容
<div class="article">
<div class="title">文章标题1</div>
<div class="title">文章标题2</div>
<div class="title">文章标题3</div>
</div>
绑定
$(".article>.title ").on("click", function(event){
alert($(this).text());
});
但是我们文章列表如果是通过js加载的, 这是绑定就失效了
这时应该直接绑定document
绑定动态加载的DOM
$(document).on("click", ".article>.title ", function(event){
alert($(this).text());
});
以上是关于jquery的事件绑定on()动态绑定的主要内容,如果未能解决你的问题,请参考以下文章
JQuery .on() 没有将点击事件绑定到动态创建的元素[重复]