如何使用JavaScript刷新页面?


当前回答

问题应该是,

如何使用JavaScript刷新页面

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

你被宠坏了。

其他回答

这适用于所有浏览器:

location.reload();

我想有很多方法会奏效:

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

如果当前页面是通过POST请求加载的,您可能需要使用

window.location = window.location.pathname;

而不是

window.location.reload();

因为如果在POST请求加载的页面上调用window.location.reload()将提示确认。

$(document).on("click", "#refresh_btn", function(event) 
{
     window.location.replace(window.location.href);
});

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

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

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

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

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