如何使用JavaScript刷新页面?


当前回答

我想有很多方法会奏效:

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

其他回答

您可能需要使用

 location.reload()

或可能需要使用

location.reload(forceGet)

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

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

您可以使用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>

下面是一些代码行,您可以使用jQuery重新加载页面。

它使用jQuery包装器并提取本地dom元素。

如果您只想在代码上获得jQuery的感觉,而不关心代码的速度/性能,请使用此选项。

只需从1到10中选择适合您的需求,或者根据模式和之前的答案添加更多内容。

<script>
  $(location)[0].reload(); //1
  $(location).get(0).reload(); //2
  $(window)[0].location.reload(); //3
  $(window).get(0).location.reload(); //4
  $(window)[0].$(location)[0].reload(); //5
  $(window).get(0).$(location)[0].reload(); //6
  $(window)[0].$(location).get(0).reload(); //7
  $(window).get(0).$(location).get(0).reload(); //8
  $(location)[0].href = ''; //9
  $(location).get(0).href = ''; //10
  //... and many other more just follow the pattern.
</script>

我想有很多方法会奏效:

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

这对我有用。

function reload(){
    location.reload(true);
}