<!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="#">点击</a>
</body>
</html>
上面的代码点击后会回到页面顶部。
解决问题:
<!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)">点击</a>
</body>
</html>
好了,问题解决\(^o^)/~
如果想给a标签添加点击事件,可以这样写
<!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()">点击</a>
</body>
<script>
function aClick() {
alert("晨落梦公子");
}
</script>
</html>