jQuery的.load()等到内容加载加载、内容、jQuery、load

2023-09-10 17:28:12 作者:浪

如何prevent jQuery的 $('身体')的负载('something.php'); 更改任何 DOM直到所有内容的 something.php (包括图片,JS)是完全 加载

How to prevent jQuery $('body').load('something.php'); from changing any DOM till all the content from something.php (including images,js) is fully loaded

-Lets说一些实际的内容是:

-Lets say some actual content is:

Hello world

something.php 内容:

image that loads for 10 seconds
20 js plugins

射击.load后()函数没有什么应该发生的,直到图像完全加载一个js文件,和然后瞬间改变的内容。

一些preloader可能会出现,但它不是主题的问题。

some preloader may appear, but its not subject of question.

----------------------------------------- -----------------------------

我该解决方案是CSS code(CSS加载之前总是DOM是建立),有跨浏览器的不透明度0。

My solution for that was css code (css is loaded always before dom is build) that has cross-browser opacity 0.

.transparent{
    -moz-opacity: 0.00;
    opacity: 0.00;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha"(Opacity=0);
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);
    filter:alpha(opacity=0);
}

和它起价内容不好的Flickr通常但并不总是p $ pvent。现在,它可以检测到某种方式的内容是通过jQuery的AJAX加载和应用一些节目超时等。但实际上的问题仍然是开放的。

And it prevent from bad flickr of content usually but not always. Now its possible to detect somehow that content is loaded by jQuery ajax and apply some show timeout and so on. But in fact question is still open.

要现在做一点简单的例子这个问题:

To make now a little more simple example for that question:

如何点击链接火.load('something.php')函数后开始$('身体')后改变DOM。负载(something.php')与3000ms延迟? (浏览器应该立即开始下载,但DOM变化具有稍后启动)

How to begin changing DOM after $('body').load('something.php') with 3000ms delay after clicking the link that fire .load('something.php') function? (Browser should start downloading instantly, but DOM changing has to be initiated later)

推荐答案

使用。获得而不是和分配的成功回调的内容:

Use .get instead and assign the contents in the success callback:

$.get('something.php', function(result) {
    $('body').html(result);
});