Home > Web Front-end > JS Tutorial > How to implement the problem of clicking the a tag to return to the top of the page in JS

How to implement the problem of clicking the a tag to return to the top of the page in JS

高洛峰
Release: 2017-01-21 10:06:18
Original
1721 people have browsed it

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
  p {
   font-size: 400px;
  }
 </style>
</head>
<body>
<p>?</p>
<a href="javascript:void(0)">点击</a>
</body>
</html>
Copy after login

The above code will return to the top of the page after clicking.

Solution to the problem:

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
  p {
   font-size: 400px;
  }
 </style>
</head>
<body>
<p>?</p>
<a href="javascript:void(0)">点击</a>
</body>
</html>
Copy after login

Okay, the problem is solved\(^o^)/~

If you want to add a click event to the a tag, you can write like this

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
  p {
   font-size: 400px;
  }
 </style>
</head>
<body>
<p>?</p>
<a href="javascript:void(0)" onclick="aClick()">点击</a>
</body>
<script>
 function aClick() {
  alert("晨落梦公子");
 }
</script>
</html>
Copy after login

The above is the problem that the editor introduces to you on how to click the a tag to return to the top of the page in JS. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. of. I would also like to thank you all for your support of the PHP Chinese website!

For more related articles on how to implement clicking the a tag to return to the top of the page in JS, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template