HTML5 已經移除了 name 屬性,因此在實現頁內錨點時請改用 id。示例效果:https://keleyi.com/keleyi/phtml/html5/9.htm
支援 Chrome、火狐、IE8 以上等瀏覽器。
以下是完整程式碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>HTML5錨點實例--柯樂義</title>
<style>
body{margin:0px;}
</style>
</head>
<body>
<div id="keleyihead"><a href="#keleyifoot">轉到底部</a></div>
<div style="background-color:#959822; width:100%;height:150px;">請滾動鼠標使頁面向下</div>
<div style="background-color:Green; width:100%;height:150px;">www.keleyi.com</div>
<div style="background-color:Red; width:100%;height:150px;">歡迎</div>
<div style="background-color:Yellow; width:100%;height:150px;">hi</div>
<div style="background-color:Silver; width:100%;height:150px;">這裡放置一些內容</div>
<div style="background-color:Aqua; width:100%;height:150px;">keleyi.com</div>
<div style="background-color:Fuchsia; width:100%;height:150px;">keleyi</div>
<div style="background-color:Green; width:100%;height:150px;">keleyi.com</div>
<div style="background-color:Blue; width:100%;height:150px;">柯樂義</div>
<div style="background-color:Olive; width:100%;height:150px;">柯樂義 監視下滾像素</div>
<div style="background-color:Purple; width:100%;height:150px;">jquery</div>
<div style="background-color:Orange; width:100%;height:150px;">完整程式碼</div>
<div style="height:200px;width:100%;">HTML5已經去掉name屬性,實現錨點時請使用id</div>
<div id="keleyifoot" style="width:100%;height:276px;text-align:center;"><a href="#keleyihead">回到頂部</a></div>
</body>
</html>
直接跳轉到頁底的示例:
https://keleyi.com/keleyi/phtml/html5/9.htm#keleyifoot