VBscript 中不再使用睡眠操作吗? [英] Is the Sleep operation no longer used in VBscript?

查看:25
本文介绍了VBscript 中不再使用睡眠操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

互联网上许多地方(包括本论坛的此处)所述的睡眠"命令不起作用.它现在是一个过时的命令吗?

The "Sleep" command as stated in many places over the internet (including here on this forum) DOES NOT WORK. Is it now an obsolete command?

我正在编写这样的 VBScript 代码:

I am writing the VBScript code like this:

sub button1_onclick()
Wscript.Sleep 1000
div1.innerHTML = textbox1.value
end sub

它应该等待 1 秒钟,然后执行那个简单的命令.这是一个非常简单的声明,但它不起作用.干净利落.每次说:

It should wait 1 second and then execute that simple command. This is an utterly simple statement but it does not work. Plain and simple. It comes up with an error every time saying:

需要的对象:'Wscript'

Object Required: 'Wscript'

推荐答案

Daniel 的回答关于上下文是绝对正确的关键在这里.尽管您没有可用的 WScript 方法,但您确实拥有完整的浏览器 DOM,包括 window.setTimeout 方法.使用 VBScript,将代码传递给 setTimeout 的语义与 JavaScript 有点不同,但它仍然是可能的:

Daniel's answer is absolutely correct about context being the key here. Although you don't have the WScript method available, you do have the full browser DOM, including the window.setTimeout method. With VBScript, the semantics of passing code to setTimeout are a little bit different than JavaScript, but it's still possible:

Sub button1_onclick()
    window.setTimeout GetRef("Delayed"), 1000
End Sub

Sub Delayed()
    div1.innerHTML = textbox1.value
End Sub

这篇关于VBscript 中不再使用睡眠操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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