如何使用JavaScript刷新页面?
当前回答
我想有很多方法会奏效:
window.location.reload();history.go(0);window.location.href=window.location.html;
其他回答
我想有很多方法会奏效:
window.location.reload();history.go(0);window.location.href=window.location.html;
下面是一些代码行,您可以使用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>
这里所有的答案都很好。由于问题指定了如何使用jquery重新加载页面,我只是想为未来的读者添加更多内容。
jQuery是一个跨平台JavaScript库,旨在简化HTML的客户端脚本。~维基百科~
因此,您将了解jquery或jquery的基础是基于javascript的。因此,在简单的事情上,使用纯javascript要好得多。
但如果您需要jquery解决方案,这里有一个。
$(location).attr('href', '');
我找到了
window.location.href = "";
or
window.location.href = null;
还进行页面刷新。
这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。
jQueryLoad函数还可以执行页面刷新:
$('body').load('views/file.html', function () {
$(this).fadeIn(5000);
});