jQuery的ready事件不会触发偏页面加载加载、事件、页面、jQuery

2023-09-10 17:25:32 作者:你的幸福、我赞助

下面是现场:包含HTML和使用jQuery libray和标签的jQuery UI插件加载其他页面的一些选项卡时的页面。问题是,当页面/ HTML加载/渲染(让我们简化这一点,并说,它只是做这样的事情$(#myDiv)负载(URL);),ready事件是不是当然的了,因为炒窗口已经装载并发射的加载事件。这意味着,没有一个页面的jQuery的东西,我想要做的负荷(部分负荷)被执行。该UI.tabs插件设计用来加载页面到其他标签,我们可以假设,其他页面可能包含自己的jQuery的...所以应该有一些解决这个方法..

Here's the situ: A page which contains html and using the jQuery libray and tabs jQuery UI plugin loads another page when some tab is clicked. The problem is that when the page/html is loaded/rendered (let's simplify this and say it's just doing something like $("#myDiv").load(url);), the ready event is not fired because of course the "window" has already loaded and fired the load event. This means that none of the jQuery things I want to do on load (partial load) of the page are executed. The UI.tabs plugin is designed to load pages into other tabs and we can assume that other pages may contain their own jQuery... so there should be some way around this..

我能想到的很恐怖的方式来克服这个问题,好像有页面所呈现的底部(加载到一个div)的脚本块,做所有的事情,我会做准备时,被解雇(你可以假定浏览器已经呈现的页面,如果脚本块被打)。然而,这是非常不好的做法。有什么建议?

I can think of very horrible ways to get over the problem, like have a script block at the bottom of the page being rendered (loaded into a div) which does all things I would do when ready is fired (as you can assume the browser has rendered the page already if the script block is hit). This however is VERY bad practise. Any suggestions?

推荐答案

Load方法提供其执行的内容已被加载后回调。

The load method offers a callback which is executed after the content has been loaded.

$("#myDiv").load(url, null, function() { 
   //do your stuff here 
});

在jQuery.com完整的文档和示例: http://docs.jquery.com/Ajax/load

 
精彩推荐
图片推荐