测试是否已加载内容 [英] test if content has been loaded

查看:60
本文介绍了测试是否已加载内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试我的div中通过innerhtml插入的内容是否已完成

loading。


这是怎么做到的?我需要它,因为我想显示一个loading ....文本

直到所有内容都被加载。

I need to test if content in my div inserted via innerhtml is done
loading.

how is this done? i need it because i want to show a "loading...." text
until all the content has be loaded.

推荐答案

Mokka于2006年16月16日在comp中写道.lang.javascript
Mokka wrote on 16 mrt 2006 in comp.lang.javascript:
我需要测试通过innerhtml插入的div中的内容是否已完成
加载。


需要吗? [你想,我想]

这是怎么做到的?我需要它,因为我想显示一个loading ....文本
直到所有内容都被加载。
I need to test if content in my div inserted via innerhtml is done
loading.
Need? [You would like, I suppose]
how is this done? i need it because i want to show a "loading...." text
until all the content has be loaded.




向我们展示您的相关代码。


你是什么在innerHTML的上下文中加载意味着什么?


-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点)



Show us your relevant code.

What do you mean by loading in the context of innerHTML?

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


您始终可以使用全局变量并使用setInterval来检查是否

变量已更改状态。我在这里假设您正在使用

异步JavaScript调用(AJAX)。


示例:


<脚本>

var g_writing_done = false;


//每2秒检查一次

var g_interv_1 = setInterval(check_writing,2000) ;


函数check_writing()

{

if(g_writing_done)

{

// innerHTML写作完成

...


//清除间隔以停止执行

clearInterval(g_interv_1);

}

}

< / script>


那里没有我所知道的建筑方式。但是当有人在这里指出

时,请向我们展示更多代码。

You can always use a global variable and use setInterval to check if
the variable has changed status. I assume here that you are using
asynchronous javascript call (AJAX).

Example:

<script>
var g_writing_done = false;

// check every 2 seconds
var g_interv_1 = setInterval(check_writing, 2000);

function check_writing()
{
if( g_writing_done )
{
// innerHTML writing is completed
...

// clear the interval to stop it executing
clearInterval(g_interv_1);
}
}
</script>

There is no built in way that I know of. But then as someone here has
pointed out, show us more code.


Crazy Code Ninja写道:
Crazy Code Ninja wrote:
您始终可以使用全局变量并使用setInterval来检查变量是否已更改状态。我在这里假设您正在使用异步JavaScript调用(AJAX)。


如果使用异步XML HTTP请求,则不需要

window.setInterval()。

示例:

< script>


'type''属性是必需的:


< script type =" text / javascript">

var g_writing_done = false;

//每2秒检查
var g_interv_1 = setInterval(check_writing,2000);
You can always use a global variable and use setInterval to check if
the variable has changed status. I assume here that you are using
asynchronous javascript call (AJAX).
If an asynchronous XML HTTP request would be used, there was no need for
window.setInterval().
Example:

<script>
The `type'' attribute is required:

<script type="text/javascript">
var g_writing_done = false;

// check every 2 seconds
var g_interv_1 = setInterval(check_writing, 2000);




这将在IE中突破< 5.0。


setInterval()是一个Window对象的方法,应该像这样引用

。必须在运行时进行先前的功能测试。


在你有最低限度的线索之前,你会停止发布建议吗?

PointedEars



This will break in IE < 5.0.

setInterval() is a method of Window objects and should be referred
to as such. A previous feature test on runtime is obligatory.

Will you stop posting advice until you have a minimum clue?
PointedEars


这篇关于测试是否已加载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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