gpt4 book ai didi

javascript - 横幅刷新代码

转载 作者:行者123 更新时间:2023-12-02 20:29:11 29 4
gpt4 key购买 nike

我有横幅代码,它与图像和超链接不同。我所需要的只是 javascript 代码,它将每 30 秒刷新一次此代码,而不刷新页面的其余部分。

此横幅代码将出现在聊天室中。我真的很感激任何帮助。横幅代码:

<script language='JavaScript' 
type='text/javascript'
src='xxxxxx/banner.php?uname=yyyy&type=2&rows=1' >
</script>

最佳答案

您应该做的第一件事是将代码包装在函数中。尝试重新调用整个脚本文件导入比仅仅调用函数要困难得多。

一旦所有内容都包装在函数中,您就可以使用 setTimeout 来调用该方法。我会做这样的事情:

function drawBanner() {
// Do stuff to draw the banner.
// Make sure you handle the case that the
// banner is already present in the DOM!
}

function onDrawBannerTimer() {
// Set this function to fire again after 30 seconds.
// Note that this will fire it roughly every 30 seconds real-time.
// You can move this statement to after the drawBanner() call
// in order to make it 30 seconds between the end of one
// invocation and the start of the next.
setTimeout(onDrawBannerTimer, 30 * 1000);
drawBanner();
}

// Trigger the first invocation when the script is loaded.
onDrawBannerTimer();

关于javascript - 横幅刷新代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4442629/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com