gpt4 book ai didi

javascript - 如何在 javascript 或 jquery 中重定向页面

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

我有一个网页。在此页面上,我有一个 DIV,它从另一个 PHP 页面获取提要。此提要也有倒计时。我希望当计数达到 0 时,只有 DIV 中的页面重定向到我选择的目的地。下面是我正在使用的:

function CountDown(t){
var s,c,countdown;
s= 6;
c=$('#count');

countdown = setInterval(function(){
c.html("Redirecting in " + s);
if (s == 0) {

window.location.href="Forums";
return false;
}
s--;
}, 1000);
}

现在 HTMl 的样子是这样的;

<html>
//header stuff
<body>
//html stuff
<div id="Mypage"></div>
//some more html stuff
</body>
</html>

相关页面位于 id = Mypage 的 DIV 中。我想要的是当倒计时达到零时页面重定向,但在这种情况下它重定向整个主页。是否可以仅将 DIV 中的页面重定向到新位置?我确信我的代码 window.location.href 是发生这种情况的原因,但我不确定如何仅在 DIV 重定向中创建页面。

最佳答案

您可以使用 jQuery.load() 将内容加载到特定的 div 中,如下所示:

$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});

要仅替换内页的正文,请从内页内的脚本中尝试以下操作:

$('body').replaceWith(data);

$('body').html(data);

关于javascript - 如何在 javascript 或 jquery 中重定向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15978605/

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