HTML, CSS

问题描述 投票:0回答:1

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>.

javascript html refresh href reload
1个回答
1
投票

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.


0
投票

You can simply do as below:

© www.soinside.com 2019 - 2024. All rights reserved.