本文介绍了如何使JavaScript延迟,然后刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的JavaScript在创建的函数结束时等待七秒钟,然后刷新页面.如果重要的话,下面将介绍我的JavaScript和HTML的重要部分...

I'd like my JavaScript to, at the end of the function I have created, wait seven seconds, and then refresh my page. If it is important, I have the vital parts of my JavaScript and HTML below...


Javascript:


Javascript:

var textfill = function () {
    var node = document.createElement("P");
    var x = document.getElementById('entertext').value;
    var textnode = document.createTextNode("The search results for: '" + x + "' will show up here");
    node.appendChild(textnode);
    document.getElementById("123").appendChild(node);
}

HTML:

HTML:

 <input type="text" id="entertext">
 <input type="button" onclick="textfill()" value="Search">
 <p id="123">
 </p>

推荐答案

function refreshPage() {
    //ensure reloading from server instead of cache
    location.reload(true);
}
function delayRefreshPage(mileSeconds) {
    window.setTimeout(refreshPage, mileSeconds);
}
var textfill = function () {
    var node = document.createElement("P");
    var x = document.getElementById('entertext').value;
    var textnode = document.createTextNode("The search results for: '" + x + "' will show up here");
    node.appendChild(textnode);
    document.getElementById("123").appendChild(node);
    delayRefreshPage(2000);
}

总结@ioseph和我的个人经历.

Summarizing @ioseph and my personal experience.

这篇关于如何使JavaScript延迟,然后刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:07