vbscript - document.getElementbyId : Object required

标签 vbscript

我在试图获取 innerHTML 的经典 ASP 页面上有一些代码。的 <div>元素。

    Dim oElm 
    Set oElm = document.getElementById("screenDiv")

    if oElm Is Nothing then
        '''
    else
        document.getElementById("screenDiv").innerHTML = ""
    end if

我已经尝试了上述方法,但出现了 Object Required 错误。

我需要做什么来解决这个错误?

最佳答案

NOTE: client side VBScript is outdated, deprecated, and doesn't work in any modern browser including newer versions of IE.



这意味着代码位于元素之前,因此当它执行时,例如
元素不存在。

要解决此问题,请在 onload 事件中执行代码:
<script type="text/vbscript">
Set window.onload = GetRef("WindowLoad")
Function WindowLoad
    Dim oElm 
    Set oElm = document.getElementById("screenDiv")
    if oElm Is Nothing then
        MsgBox("element does not exist")
    else
        oElm.innerHTML = ""
    end if
End Function
</script>

正确方法归功于 Korikulum ,官方文档可以找到 here

Live test case 。 (仅限IE浏览器)

关于vbscript - document.getElementbyId : Object required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304039/

相关文章:

asp.net - VbScript ASP : checking checkbox

vbscript - 如何使用 VBScript 和 WMI 列出本地管理员组的所有成员

vbscript - 重定向到 VBS 中的标准输出

windows - vbscript 下载文件(绕过无效证书错误)

javascript - 将句子大小写应用于可能包含 HTML 的字符串

java - VBScript:正则表达式匹配不正确的注册表值时出错

windows - 按数字对文本文件的内容进行排序

vb.net - 正确地将字符串转换为流

.net - 在 VBScript (COM-interop) 中确定 .Net 方法后缀号

excel - 将 VBA 转换为 VBScript 以删除列中的重复项