我使用 vbscript 制作了这个简单的 html 应用程序。
<html>
<head>
<title>Example</title>
<script type="text/vbscript" src="scr1.vbs"></script>
<script type="text/vbscript" src="scr2.vbs"></script>
</head>
<body>
<p>Example</P>
<button onClick="scr1">scr1</button>
<button onClick="Scr2()">scr1</button>
</body>
</html>
现在脚本 1 和 2 都需要很长时间才能完成。当其中一个脚本正在运行时,应用程序挂起。有什么方法可以让它异步吗?
vbscripts 与此类似。
Set fso = CreateObject("Scripting.FileSystemObject")
For Each oFile In fso.GetFolder(sFolder).Files
If LCase(fso.GetExtensionName(oFile.Name)) = "txt" Then
set oFile = fso.OpenTextFile(oFile)
Do While oFile.AtEndOfStream <> True
TextLine = TextLine & oFile.ReadAll
Loop
End if
Next
Set regEx_ = new regExp
With regEx_
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "pattern 1"
TextLine = regEx_.replace(TextLine, "mmrk$&")
.Pattern = "pattern 2"
TextLine = regEx_.replace(TextLine, "mmrk$&")
'and 100 more such complex regex replaces
End With
set Temp = fso.CreateTextFile(TempFile, True)
Temp.Write TextLine
Temp.Close
Set Temp = Nothing
这里是否还有任何范围可以使其异步?
最佳答案
要异步运行脚本,您需要脚本中指定的异步:
<script src="demo_async.js" async></script>
这里有一些关于这个主题的信息: https://css-tricks.com/async-attribute-scripts-bottom/
关于html - 如何在 HTML 应用程序中异步运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419454/