我有一个非常长的 VBScript 代码,它在 HTA 中运行。该脚本包括 DOM 操作、DLL 调用和其他脚本。现在我遇到了一个问题,因为有很多脚本会暂停 HTML 解析,因此需要花费大量时间在屏幕上呈现文本。
现在我计划创建一个简单的延迟,它会阻止代码执行,但不会阻止 HTML 解析。但我不知道该怎么做。
更新
这是我想要的示例代码(抱歉,请不要介意我对 HTA vbs 不熟悉的语法)
Sub Window_Onload()
Call Main()
End Sub
Sub Main()
Dim delay
el.innerHtml = "Please"
el2.innerHtml = "Help"
el3.innerHtml = "me"
'more scripts here
'more scripts here
'more scripts here
'more scripts here
el4.innerHtml = "this element is dependent to other scripts"
el5.innerHtml = "this element is dependent to other scripts"
el6.innerHtml = "this element is dependent to other scripts"
delay = 2
Call PauseAndRenderHtml(delay) 'this function will block the code execution
'but not the html parsing
'more scripts here
Do While True
'very long scripts that loops and pause, loops and pause........
Loop
End Sub
Sub PauseAndRenderHtml(timeToBreath)
'Take a breath :)
'breath/pause for timeToBreath seconds
End Sub
我需要函数PauseAndRenderHtml()
最佳答案
也许是一个计时器,如描述的 here可能有帮助:
<head>
<title>Sample</title>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="Sample"
>
</head>
<script language="VBScript">
idTimer = window.setTimeout(GetRef("PausedSection"), 10000, "VBScript")
Sub PausedSection
ContinueWork
window.clearTimeout(idTimer)
End Sub
Sub ContinueWork
'other code here
End Sub
</script>
<body>
...
</body>
关于javascript - 给 HTML 时间来呈现其文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435550/