如何使用JavaScript刷新页面?
当前回答
<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>
<script>
$(document).on('click','#refresh',function(){
location.reload(true);
});
</script>
其他回答
<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>
<script>
$(document).on('click','#refresh',function(){
location.reload(true);
});
</script>
您可以使用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>
这适用于所有浏览器:
location.reload();
use
location.reload();
or
window.location.reload();
下面是一些代码行,您可以使用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>