ajax加载后再次运行jQuery ready块? [英] Run jQuery ready block again after ajax loaded?

查看:109
本文介绍了ajax加载后再次运行jQuery ready块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否在这里问正确的问题,但基本上我正在插入带有ajax请求的html:

I'm not sure if I'm asking the right question here, but basically I'm inserting html with an ajax request:

// data-active_chart
if ($("#charts").attr("data-active_chart") == "barchart") {
  $.ajax({
    url: $("#charts").attr("data-path") + "/barchart",
    success: function(data) {
      $('#charts').html(data);
      console.log('Load was performed.');
    }
  });
}

我的HTML类似于:

<div id="charts" data-active_chart="barchart" data-path="http://example.com/something">

</div>

但关键是我需要jQuery来了解更新的DOM,就像我需要我的工具提示一样这样在插入的HTML中工作,以及插入的HTML中的一堆其他东西都需要响应JS,我该如何以最佳实践方式做到这一点?

But the point is I need jQuery to be aware of the updated DOM, like I need my tool tips and such to work in the HTML that's been inserted, along with a bunch of other things in the inserted HTML all need to respond to JS, how do I do this in a best practices way?

推荐答案

如果需要绑定在DOM更改后发生的事件,请使用 jQuery直播

If you need to bind events that will occur after the DOM has changed use jQuery live!

这篇关于ajax加载后再次运行jQuery ready块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆