getElementByID return null(因为还没有加载)
getElementByID return null (because not loaded yet)
大家好,
我正在尝试通过 javascript 中的 ID 获取一个元素,它 returns 我 null
。
实际上,当 DOM 时此元素未完全加载是因为插件 Restrict Content Pro(目标元素的来源)在页面加载后发出请求 (请参阅参考下图).
我写的临时解决方案基本上是 getElementByID
函数上的 2 秒 setTimeOut
,这有点……残酷。 ☺
如果插件加载时间超过 2 秒,它将无法运行。
所以,我的问题是:您知道正确的方法吗?
类似于
- while returns null
try to get it
- when returns element
stop the loop
good to know : document.onload
or window.onlaod
won't work since the plugin loads element after the page is fully display.
提前致谢!
我的解决方案:
do {
var getId = getElementByID();
if(getID!=null){
// to do
}
}
while (getId==null);
大家好,
我正在尝试通过 javascript 中的 ID 获取一个元素,它 returns 我 null
。
实际上,当 DOM 时此元素未完全加载是因为插件 Restrict Content Pro(目标元素的来源)在页面加载后发出请求 (请参阅参考下图).
我写的临时解决方案基本上是 getElementByID
函数上的 2 秒 setTimeOut
,这有点……残酷。 ☺
如果插件加载时间超过 2 秒,它将无法运行。
所以,我的问题是:您知道正确的方法吗?
类似于
- while returns null
try to get it
- when returns element
stop the loop
good to know :
document.onload
orwindow.onlaod
won't work since the plugin loads element after the page is fully display.
提前致谢!
我的解决方案:
do {
var getId = getElementByID();
if(getID!=null){
// to do
}
}
while (getId==null);