我在经典ASP网页上有一些代码试图获取innerHTML
元素的<div>
。
Dim oElm
Set oElm = document.getElementById("screenDiv")
if oElm Is Nothing then
'''
else
document.getElementById("screenDiv").innerHTML = ""
end if
我已尝试过以上操作,但我收到了Object Required错误。
我需要做些什么来解决这个错误?
答案 0 :(得分:6)
注意:客户端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>
正确的方法归功于Korikulum,可以找到官方文档here。
Live test case。 (仅限IE)