如何使用JavaScript刷新页面?


当前回答

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

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

其他回答

下面是一些代码行,您可以使用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>

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

history.go()

简单的Javascript解决方案:

 location = location; 

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

问题应该是,

如何使用JavaScript刷新页面

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

你被宠坏了。

这对我有用。

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