[英]How do I refresh a page when clicking on a href? | HTML, CSS
What do I have:我有什么:
HTML, CSS, JS HTML,CSS,JS
What do I need:我需要什么:
Reload a page when clicking on <a href>
.单击
<a href>
时重新加载页面。
What do I know:我知道什么:
I can reload a page using window.location.reload()
.我可以使用
window.location.reload()
重新加载页面。 To use it in HTML code, I have to put it into <script>
tags.要在 HTML 代码中使用它,我必须将它放入
<script>
标签中。
What don't I know:我不知道的是:
How to execute this script code when clicking on <a href>
.单击
<a href>
时如何执行此脚本代码。
My code:我的代码:
<ul>
....
<a href="#" class="currentpage"><li>About us</li></a>
</ul>
What have I tried:我尝试了什么:
Nothing yet.还没有。 I have no idea how to link the
<script>
with <a href>
.我不知道如何将
<script>
与<a href>
链接起来。
If you want to reload the current page you can use this code:如果要重新加载当前页面,可以使用以下代码:
<a href="#" onclick="myFunction()" class="currentpage"><li>About us</li></a> <script> function myFunction() { window.location.reload(); } </script>
It will execute the given function after you click on the link.单击链接后,它将执行给定的 function。
You can simply do as below:您可以简单地执行以下操作:
<a href="javascript:window.location.reload();"><li>Refresh Page</li></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.