Table of Contents
HTML 教程目录
第一章" >第一章
第二章" >第二章
第三章" >第三章
第四章" >第四章
第五章" >第五章
第六章" >第六章
第七章" >第七章
第八章" >第八章
使用 name 属性还是 id 属性?
Home Web Front-end HTML Tutorial HTML系列(五):超链接_html/css_WEB-ITnose

HTML系列(五):超链接_html/css_WEB-ITnose

Jun 24, 2016 am 11:25 AM

     标签定义超链接,最重要的属性是 href 属性,它指示链接的目标。通过将href属性设定不同类型的值可以使链接指向不同类型的链接地址:内部链接、外部链接、锚链接。

     内部链接指的是同一域名网站内部页面的相互链接;外部链接指从某一域名网页指向外部域名网站的链接;锚链接指从某个域名外部所有以文字带超链接指向这个域名的链接,是影响网站关键词在搜索引擎中排名的重要因素。

一、指向外部的超链接

     链接文本

二、相对路径

     当源文件和引用文件在同一个目录里,直接引用文件名;使用../表示源文件所在目录的上一级目录,../../表示源文件所在目录的上上级目录,以此类推;引用下级目录文件,直接写下级目录文件名,用/隔开。

三、页面内超链接

     当一张页面上篇幅较长,用户查找困难,就可以用页面内超链接作为导航。页面内超链接也称作锚链接,类似于书签的功能,实现在页面内不同位置的跳转,用户不需要反复拖动滚动条进行定位。

     做法:通过a的name属性定义锚的名称,通过a的href属性可以根据name跳到对应的锚。

     示例代码:

 1 <body> 2 <h1 id="HTML-教程目录">HTML 教程目录</h1> 3  4 <ul> 5 <li><a href="#C1">第一章</a></li> 6 <li><a href="#C2">第二章</a></li> 7 <li><a href="#C3">第三章</a></li> 8 <li><a href="#C4">第四章</a></li> 9 <li><a href="#C5">第五章</a></li>10 <li><a href="#C6">第六章</a></li>11 <li><a href="#C7">第七章</a></li>12 <li><a href="#C8">第八章</a></li>13 </ul>14 15 <h2 id="a-name-C-第一章-a"><a name="C1">第一章</a></h2>16 <p>本章讲解的内容是 ... ...</p>17 18 <h2 id="a-name-C-第二章-a"><a name="C2">第二章</a></h2>19 <p>本章讲解的内容是 ... ...</p>20 21 <h2 id="a-name-C-第三章-a"><a name="C3">第三章</a></h2>22 <p>本章讲解的内容是 ... ...</p>23 24 <h2 id="a-name-C-第四章-a"><a name="C4">第四章</a></h2>25 <p>本章讲解的内容是 ... ...</p>26 27 <h2 id="a-name-C-第五章-a"><a name="C5">第五章</a></h2>28 <p>本章讲解的内容是 ... ...</p>29 30 <h2 id="a-name-C-第六章-a"><a name="C6">第六章</a></h2>31 <p>本章讲解的内容是 ... ...</p>32 33 <h2 id="a-name-C-第七章-a"><a name="C7">第七章</a></h2>34 <p>本章讲解的内容是 ... ...</p>35 36 <h2 id="a-name-C-第八章-a"><a name="C8">第八章</a></h2>37 <p>本章讲解的内容是 ... ...</p>38 39 </body>
Copy after login

使用 name 属性还是 id 属性?

     在 HTML 4.0 之前的版本中,只有使用 标签的 name 属性才能创建片段标识符。随着 HTML 4.0 中 id 属性的出现,所有 HTML 或 XHTML 元素都可以是片段标识符。这是因为 id 标识符几乎可以用在所有的标签中。 标签为了能够和以前的版本相兼容而保留了 name 属性,同时也可以使用 id 属性。这些属性可以相互交换使用,可以把 id 属性看作是 name 属性的升级版本。name 和 id 属性都可以与 href 属性结合起来使用,这样一个 标签就可以同时作为超链接和片段标识符使用。

     可以简单地将片段标识符看作是对许多编程语言中普遍使用的 goto 语句标签的 HTML 模拟。 标签中的 name 属性或者 或其他标签中的 id 属性会在文档中放置一个标识。当标签用于链接到该文档时,就等于告诉浏览器要转到(goto)该标识。

     id 或 name 属性的值可以是引号引起来的任何字符串。字符串必须是唯一的标记,不能在同一文档中的其他 name 或 id 属性中重复使用,但是可以在不同的文档中再次使用。

     上面的示例代码的name可以替换成id。

 

未完待续。。。。。。。。。。。。。。。。。。。。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

See all articles