如何使用JavaScript重定向到当前页面? [英] How do I redirect to the current page using JavaScript?

查看:82
本文介绍了如何使用JavaScript重定向到当前页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击链接后,它应该重定向到当前页面。如何使用JavaScript执行此操作?

On clicking a link, it should redirect to the current page. How do I do this with JavaScript?

推荐答案

假设您的意思是链接应该刷新当前页面,您可以使用 window.location.reload()。在jQuery中它看起来像这样:

Assuming you mean the link should refresh the current page, you can use window.location.reload(). In jQuery it would look like this:

<a href="#" id="myLink">Refresh current page</a>



$("#myLink").click(function() {
    window.location.reload();
});

在普通JS中它看起来像这样:

In plain JS it would look like this:

document.querySelector("#myLink").addEventListener('click', function() {
    window.location.reload();
});

这篇关于如何使用JavaScript重定向到当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆