本文转载至http://www.cnblogs.com/chenluomenggongzi/p/5950670.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 <style>
7 p{
8 font-size: 400px;
9 }
10 </style>
11 </head>
12 <body>
13 <p>?</p>
14 <a href="#">点击</a>
15 </body>
16 </html>
上面的代码点击后会回到页面顶部。
解决问题:
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 <style>
7 p {
8 font-size: 400px;
9 }
10 </style>
11 </head>
12 <body>
13 <p>?</p>
14 <a href="javascript:void(0)">点击</a>
15 </body>
16 </html>
好了,问题解决\(^o^)/~
如果想给a标签添加点击事件,可以这样写
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 <style>
7 p {
8 font-size: 400px;
9 }
10 </style>
11 </head>
12 <body>
13 <p>?</p>
14 <a href="javascript:void(0)" onclick="aClick()">点击</a>
15 </body>
16 <script>
17 function aClick() {
18 alert("晨落梦公子");
19 }
20 </script>
21 </html>