我有一个是试图获得一个传统的ASP页面上的一些代码,innerHTML一个的<div>元素.
Dim oElm
Set oElm = document.getElementById("screenDiv")
if oElm Is Nothing then
'''
else
document.getElementById("screenDiv").innerHTML = ""
end if
Run Code Online (Sandbox Code Playgroud)
我已经尝试了上述但我得到了Object Required错误.
我需要做些什么来解决这个错误?
注意:客户端VBScript已过时,已弃用,并且不适用于任何现代浏览器,包括较新版本的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>
Run Code Online (Sandbox Code Playgroud)
正确的方式归功于Korikulum,官方文档可以在这里找到.
现场测试案例.(仅限IE)