如何使用JavaScript刷新页面?


当前回答

简单的Javascript解决方案:

 location = location; 

<buttonClick=“location=location;”>重新加载</button>

其他回答

您可能想使用

location.reload(forceGet)

forceGet是一个布尔值,也是可选的。

默认值为false,从缓存中重新加载页面。

如果您希望强制浏览器从服务器获取页面,以清除缓存,请将此参数设置为true。

或者只是

location.reload()

如果您想快速方便地使用缓存。

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

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

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

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

$(location).attr('href', '');
<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>

<script>
$(document).on('click','#refresh',function(){
   location.reload(true);
});
</script>

在按钮标记中使用onclick=“return location.reload();”。

<button id="refersh-page" name="refersh-page" type="button" onclick="return location.reload();">Refesh Page</button>

我想有很多方法会奏效:

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