如何使用JavaScript刷新页面?


当前回答

这里所有的答案都很好。由于问题指定了如何使用jquery重新加载页面,我只是想为未来的读者添加更多内容。

jQuery是一个跨平台JavaScript库,旨在简化HTML的客户端脚本。~维基百科~

因此,您将了解jquery或jquery的基础是基于javascript的。因此,在简单的事情上,使用纯javascript要好得多。

但如果您需要jquery解决方案,这里有一个。

$(location).attr('href', '');

其他回答

问题应该是,

如何使用JavaScript刷新页面

window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another

你被宠坏了。

可能最短(12个字符)-使用历史

history.go()

您可以使用JavaScript location.reload()方法。此方法接受布尔参数。正确或错误。如果参数为真;页面总是从服务器重新加载。如果是假的;这是默认设置,或者使用空参数浏览器从其缓存中重新加载页面。

带真参数

<button type="button" onclick="location.reload(true);">Reload page</button>

带默认/假参数

 <button type="button" onclick="location.reload();">Reload page</button>

使用jquery

<button id="Reloadpage">Reload page</button>
<script type="text/javascript">
    $('#Reloadpage').click(function() {
        location.reload();
    }); 
</script>

我想有很多方法会奏效:

window.location.reload();history.go(0);window.location.href=window.location.html;

有很多方法可以重新加载当前页面,但使用这些方法,您可以看到页面更新,但不会有很少的缓存值,因此要克服这个问题,或者如果您希望发出硬请求,请使用以下代码。

    location.reload(true);
    //Here, it will make a hard request or reload the current page and clear the cache as well.


    location.reload(false); OR location.reload();
    //It can be reload the page with cache