How to click the a tab to return to the top of the page in JS
- 2021-07-12 05:14:20
- OfStack
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
p{
font-size: 400px;
}
</style>
</head>
<body>
<p>?</p>
<a href="#"> Click </a>
</body>
</html>
The above code will go back to the top of the page after clicking.
Problem solving:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
p {
font-size: 400px;
}
</style>
</head>
<body>
<p>?</p>
<a href="javascript:void(0)"> Click </a>
</body>
</html>
Ok, problem solved\ (^ o ^)/~
If you want to add a click event to the a tag, you can write this
<!DOCTYPE html>
<html lang="en">
<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()"> Click </a>
</body>
<script>
function aClick() {
alert(" Childe of Dreams in the Morning ");
}
</script>
</html>