html - 如何在 HTML 应用程序中异步运行脚本?

标签 html asynchronous vbscript hta

我使用 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/

相关文章:

asp.net-ajax - AJAX - 如何将值传递回服务器

javascript - 将异步 jQuery Dialog 更改为同步?

c# - 如何在没有异步 CTP 的情况下实现等待

vba - 传递现有的 FileSystemObject 或创建多个实例

javascript - AngularJS 属性在第一次调用时未绑定(bind)

html - 不应该出现的新行

javascript - 在 jQuery 中引用 CSS 属性

html - Css 转换不适用于网格

xml - 如何使用 vbscript 和经典 asp 在 xml 中选择 SingleNode?

string - VBScript 有 substring() 函数吗?