如何使用jQuery刷新页面?
方法 1:使用 location.reload(): location.reload() 方法重新加载当前网页,模拟点击浏览器上的刷新按钮。传递给该方法的可选 true 参数用于强制页面从服务器加载并忽略浏览器缓存。
句法:
location.reload(true)
例子:
How to refresh a page
using jQuery?
GeeksforGeeks
How to refresh a page
using jQuery?
GeeksforGeeks is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
方法 2:使用 history.go(0): history.go() 方法根据传递给它的参数从浏览器历史记录中加载一个 URL。如果传递的参数为“0”,则重新加载当前页面。
句法:
history.go(0);
例子:
How to refresh a page
using jQuery?
GeeksforGeeks
How to refresh a page
using jQuery?
GeeksforGeeks is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
方法三:在当前页面中使用location.replace:可以使用location.replace()方法,将location.pathname作为参数传递。 location.pathname 返回当前 url 并将其传递给 location.replace() 重新加载当前页面。
句法:
location.replace(location.pathname);
例子:
How to refresh a page
using jQuery?
GeeksforGeeks
How to refresh a page
using jQuery?
GeeksforGeeks is a computer science
portal with a huge variety of well
written and explained computer science
and programming articles, quizzes
and interview questions.
输出:
- 点击按钮前:
- 点击按钮后:
jQuery 是一个开源 JavaScript 库,它简化了 HTML/CSS 文档之间的交互,它以其“少写,多做”的理念而广为人知。
您可以按照此 jQuery 教程和 jQuery 示例从头开始学习 jQuery。