是否准备好jQuery ready事件? [英] Refire the jQuery ready event?

查看:104
本文介绍了是否准备好jQuery ready事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上使用jQuery $(document).ready()事件。一切都很好,除了
如果我使用Ajax调用加载数据, $(document).ready()事件不会触发。我猜它的行为是因为页面已经加载了,我只是将更多的数据从Ajax响应中添加到DOM中。

I am using the jQuery $(document).ready() event on page. All is fine, except that if I am loading data using Ajax calls, the $(document).ready() event does not fire. I guess that it behave in such way because the page was already loaded and I am just adding more data from the Ajax response to the DOM.

我怎样才能重新启动 ready event?

How can i refire the ready event ?

推荐答案

如果你需要执行一些额外的Javascript,你可能会使用你调用Ajax回调onComplete事件的函数:

If you need to execute some additionnal Javascript, you might use a function that you call upon Ajax callback onComplete event :

function initJS(){
    //your code here
}

$.ajax({
  url: 'ajax/test.html',
  success: function(data){
  },
  complete: function(){
        initJS();
  }
});

这篇关于是否准备好jQuery ready事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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