我在试图获取 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/