《html重点标签》-<a></a>标签

235 阅读1分钟

<a></a>标签

属性: href

取值:

  1. 网址: 例:baidu.com

  2. 路径: 例:/a/b/c.html 或者 a/b/c.html 以及 index.html,./index.html ,其中a,b为目录

  3. 伪协议:

    ①:href="javascript:;"

    ②: mailto:邮箱

    ③:tel:手机号

  1. 当href值为空时:

可通过id找到该行代码行。

例:

<p id="xx">代码一</p>
<p>代码二</p>
<p>代码三</p>
<a href="#xx">空链接</a>

当点击空链接时,代码行过多时,页面会自动回滚到该行。

另外,空链接默认自动回滚顶部。

属性: target

取值:_blank,_self,_top,_parent

_blank:在新页面打开网址

_self:在当前页面打开网址

_parent:在上一层页面打开

_top:在最顶层页面打开

例:

含有index.html,index1.html,index2.html三个页面

index.html:

<iframe src="index1.html">//嵌套一个index1.html页面
<a href="https://www.baidu.com" target="">baidu</a>
</iframe>

index1.html:

 <iframe src="index2.html">//嵌套一个index2.html页面
<a href="https://www.google.com" target="">google</a>
 </iframe>

index2.html

<a href="https://www.google.com" target="" >google</a>

target取值:

_blank: 在新页面打开。当三个页面都取值_blank时都是新页面打开。

_self: 当前页面打开。当三个页面都取值_self时都是在自身页面打开。

_parent: 在上一层页面打开。

例:当index1中的a标签target为_parent时,在被嵌套的页面打开,也就是index。 同理index2在index1中打开

_top:在最顶层页面打开。

index嵌套index1,index1嵌套index2,所以index1和index2的最顶层页面都为index。

所以当index1和index2的target的取值都为_top时,均在index页面打开。