方法1:使用location.reload():location.reload()方法重新加载当前网页, 模拟在浏览器上单击刷新按钮。传递给该方法的可选true参数用于强制从服务器加载页面并忽略浏览器缓存。
语法如下:
location.reload(true)
例子:
<
!DOCTYPE html>
<
html >
<
head >
<
title >
How to refresh a page
using jQuery?
<
/ title >
<
script src =
"https://code.jquery.com/jquery-3.3.1.min.js" >
<
/ script >
<
/ head >
<
body >
<
h1 style = "color: green" >
lsbin
<
/ h1 >
<
b >
How to refresh a page
using jQuery?
<
/ b >
<
p >
lsbin is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
<
/ p >
<
button type = "button" >
Button to Reload page
<
/ button >
<
script type = "text/javascript" >
$(document).ready(function () {
$("button").click(function () {
location.reload(true);
alert('Reloading Page');
});
});
<
/ script >
<
/ body >
<
/ html >
方法2:使用history.go(0):history.go()方法根据传递给它的参数从浏览器的历史记录中加载URL。如果传递的参数为" 0", 则会重新加载当前页面。
语法如下:
history.go(0);
【如何使用jQuery刷新页面(代码示例)】例子:
<
!DOCTYPE html>
<
html >
<
head >
<
title >
How to refresh a page
using jQuery?
<
/ title >
<
script src =
"https://code.jquery.com/jquery-3.3.1.min.js" >
<
/ script >
<
/ head >
<
body >
<
h1 style = "color: green" >
lsbin
<
/ h1 >
<
b >
How to refresh a page
using jQuery?
<
/ b >
<
p >
lsbin is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
<
/ p >
<
button type = "button" >
Button to Reload page
<
/ button >
<
script type = "text/javascript" >
$(document).ready(function () {
$("button").click(function () {
history.go(0);
alert('Reloading Page');
});
});
<
/ script >
<
/ body >
<
/ html >
方法3:在当前页面上使用location.replace:可以将location.replace()方法与location.pathname作为参数一起使用。 location.pathname返回当前网址, 并将其传递给location.replace()重新加载当前页面。
语法如下:
location.replace(location.pathname);
例子:
<
!DOCTYPE html>
<
html >
<
head >
<
title >
How to refresh a page
using jQuery?
<
/ title >
<
script src =
"https://code.jquery.com/jquery-3.3.1.min.js" >
<
/ script >
<
/ head >
<
body >
<
h1 style = "color: green" >
lsbin
<
/ h1 >
<
b >
How to refresh a page
using jQuery?
<
/ b >
<
p >
lsbin is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
<
/ p >
<
button type = "button" >
Button to Reload page
<
/ button >
<
script type = "text/javascript" >
$(document).ready(function () {
$("button").click(function () {
location.reload(true);
alert('Reloading Page');
});
});
<
/ script >
<
/ body >
<
/ html >
输出如下:
在单击按钮之前:
文章图片
单击按钮后:
文章图片
推荐阅读
- Scala中的字符串用法指南和代码实例
- 如何理解C语言中的extern关键字(通俗解释)
- Python如何根据长度将字符串列表拆分为子列表()
- PHP如何使用gmp_cmp()函数(代码实例)
- 算法(如何打印树中所有到根的距离为k的节点())
- 雨林木风windows64纯净版最新系统推荐
- 电脑公司windows7旗舰版最新系统推荐
- 雨林木风win7纯净版64gho最新系统推荐
- 系统之家w7旗舰版正版系统32位最新系统推荐