如何申请了jQuery元素没有可用的document.ready? [英] How to Apply jQuery to Elements Not Available at Document.Ready?

查看:108
本文介绍了如何申请了jQuery元素没有可用的document.ready?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用该网站的的jQuery UI选项卡到的通过AJAX 加载内容(在这种情况下,每个标签是由部分页面)。这工作得很好,我很高兴与结果。然而,一个问题,我已多次遇到的是,当我包括在我的master.js文件的jQuery(我使用的网站JavaScript),它并不适用于通过AJAX加载任何东西。例如,我想喜欢简单的东西:

The website I am developing uses jQuery UI tabs to load content via AJAX (in this case, each tab is made up of a partial page). This works well, and I am happy with those results. However, one problem I have repeatedly come across is that when I include jQuery within my master.js file (which I use for site-wide Javascript), it DOES NOT apply to anything that is loaded in via AJAX. For example, I tried something simple like:

// Theme all the buttons with jQuery UI themes.
$('input:button').button();

不过,在标签上所有的按钮都没有主题恰如其分。

However, all the buttons on the tabs are not themed appropriately.

我该如何解决这个问题?我在想东西 jQuery的.live()函数,但无论是负担和准备就绪事件似乎并没有奏效。这已成为一个pretty的令人沮丧的问题,从而可以提供将是最AP preciated任何帮助。

How do I fix this? I was thinking something with jQuery's .live() function, but both the 'load' and the 'ready' events don't appear to be working. This has become a pretty frustrating problem so any help that can be provided would be most appreciated.

推荐答案

您可以将其应用到您的AJAX回调这些新的元素:

You can apply it to those new elements in your AJAX callback:

$.ajax({
    url:'/some/path',
    success: function( resp ) {
        var $newElements = $(resp);  //create jQuery object of new elements
        $newElements.find('input:button').button();  // call .button() on inputs
        $newElements.appendTo('body');  // append to wherever
    }
});

我不知道什么是发生在你的AJAX的回调,但是这应该给你的总体思路。

I have no idea what is happening in your AJAX callback, but this should give you the general idea.

这篇关于如何申请了jQuery元素没有可用的document.ready?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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