我们在我们的网站上使用www.livechatinc.com LiveChat。在我们的页面加载之后,他们将livechat代码写到我们的页面上。我想将livechat div动态定位在我们的页面上,在页面加载之后。如果我尝试使用jQuery document.ready来完成这个任务,它就不能工作,因为livechat当时不在DOM中。我是否可以编写一些jQuery函数来继续检查div的DOM,一旦找到该div,我就可以定位它并停止检查。
发布于 2014-05-20 20:48:25
我从来没有特别使用过LiveChat,但是您可能可以使用setInterval
来完成这一任务。这允许您每隔几毫秒运行一次函数。例如,
$(document).ready(function(){
myInterval = setInterval(function(){
//run something like this every 3 seconds
var livechat = document.getElementById("livechat-div");
if(livechat){ //check if the div exists
//if it does, position div
//clear the interval since we no longer need to look for the div
clearInterval(myInterval);
}
}, 3000);
});
http://jsfiddle.net/HNRDe/
https://stackoverflow.com/questions/23749686
复制相似问题