常用

这里有个文章列表, 通过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());
});

相关文章:

  • 2021-05-19
  • 2022-01-11
  • 2021-07-24
  • 2021-07-26
  • 2022-12-23
  • 2022-01-11
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-01-27
  • 2021-08-19
  • 2021-05-20
  • 2021-09-07
  • 2022-12-23
相关资源
相似解决方案