1. 锚点链接 #id
锚点链接可以跳转到页面内指定位置。
第一步:给目标元素设置 id;第二步:href="#id"。
演示效果:
跳转到第一章 |
跳转到第二章 |
回到顶部
这里是页面顶部
(中间留空,方便观察跳转效果)
第一章
这是第一章的内容...
(中间留空,方便观察跳转效果)
第二章
这是第二章的内容...
1<a href="#section1">跳转到第一章</a>
2<a href="#section2">跳转到第二章</a>
3<a href="#top">回到顶部</a>
4
5<div id="top">页面顶部</div>
6<div id="section1">第一章内容</div>
7<div id="section2">第二章内容</div>
2. 邮件链接 mailto:
mailto: 点击后打开邮件客户端。
可以预填收件人、主题、正文。
1<a href="mailto:test@example.com">发送邮件</a>
2
3<a href="mailto:test@example.com?subject=你好&body=这是邮件内容">
4 发送带主题的邮件
5</a>
3. 下载链接 download
download 属性让链接下载文件而不是跳转。
属性值是下载后的文件名(可选)。
1<a href="file/test.pdf" download>下载PDF</a>
2
3<a href="file/image.jpg" download="我的图片.jpg">
4 下载图片(自定义文件名)
5</a>
4. 图片链接
用 <a> 标签包裹 <img>,点击图片跳转。
1<a href="https://www.example.com">
2 <img src="https://via.placeholder.com/150" alt="点击跳转">
3</a>
5. target 属性
target 属性控制链接打开方式:
_blank 新窗口 | _self 当前窗口(默认)
_parent 父窗口 | _top 最顶层窗口
1<a href="https://www.example.com" target="_blank">_blank: 新窗口打开</a>
2<a href="https://www.example.com" target="_self">_self: 当前窗口打开</a>
3<a href="https://www.example.com" target="_parent">_parent: 父窗口打开</a>
4<a href="https://www.example.com" target="_top">_top: 最顶层窗口打开</a>
6. 电话链接 tel:
tel: 点击后拨打电话(手机端常用)。
演示效果:
拨打电话:13800138000
1<a href="tel:13800138000">拨打电话:13800138000</a>