单击href时如何刷新页面? | HTML,CSS

What do I have:

HTML, CSS, JS

What do I need:

Reload a page when clicking on <a href>.

What do I know:

I can reload a page using window.location.reload(). To use it in HTML code, I have to put it into <script> tags.

What don't I know:

How to execute this script code when clicking on <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>.

评论
看!灰鸡
看!灰鸡

您可以简单地执行以下操作:

<a href="javascript:window.location.reload();"><li>Refresh Page</li></a>
点赞
评论
时间在怂恿
时间在怂恿

如果要重新加载当前页面,可以使用以下代码:

<a href="#" onclick="myFunction()" class="currentpage"><li>About us</li></a>

<script>
function myFunction() {
  window.location.reload();
}
</script>

单击链接后,它将执行给定的功能。

点赞
评论