html中的href属性

描述 (Description)

The href defines the document to which the link leads. This may be a web page in the same directory, a page somewhere else on the same server, a location within the current page, or a web page—or any another kind of document—stored on another server.

href定义链接指向的文档。 这可能是同一目录中的网页,同一服务器上其他位置的网页,当前页面中的位置,或者是另一台服务器上存储的网页(或任何其他类型的文档)。

The example shows a link between two documents in the same directory, but if the cake list document was in a directory that’s one level higher than the referencing document, the syntax would be as follows:

该示例显示了同一目录中两个文档之间的链接,但是如果蛋糕列表文档位于比引用文档高一级的目录中,则语法如下:

<a href="../cakes.html">lovely range of cakes</a>

Here, ../ equates to the instruction, “move up one directory in the hierarchy.”

在这里,.. /等于指令“在层次结构中上移一个目录”。

You can also reference a document relative to the web site’s root (the file or folder after the domain name):

您还可以引用相对于网站根目录(域名后的文件或文件夹)的文档:

<a href="/cakes.html">lovely range of cakes</a> 

This link basically instructs the browser to “link to the document cakes.html that can be found in www.mydomain.com/.” This is a very handy way of referencing documents, as you could move the document containing the link to any location on the file system without breaking the link.

该链接基本上指示浏览器“链接到可在www.mydomain.com/中找到的cakes.html文档。” 这是引用文档的一种非常方便的方法,因为您可以将包含链接的文档移动到文件系统上的任何位置,而无需断开链接。

If you’re linking to a document (of whatever type) that’s held on another server, you’d express the href using a complete URI, like so:

如果要链接到另一台服务器上保存的文档(任何类型的文档),则可以使用完整的URI来表示href,如下所示:

<a href="http://www.cakebrothers.com/cakes.html">lovely range of cakes</a>

In a link to another section within the same page, the destination is identified in the href attribute by a hash symbol combined with the id attribute of the destination. This notation is known as a fragment identifier, and is shown below:

在指向同一页面内另一部分的链接中,目标是在href属性中由哈希符号与目标的id属性组合而成的。 该符号称为片段标识符,如下所示:

<!-- Here is the link -->
<p>You can check the facts by reading the
<a href="#refs">references at the end of this article</a></p>
⋮
<!-- Here is the link's destination -->
<h3><a id="refs" href="#refs">References</a></h3> 

Note these points from the example above:

请注意以上示例中的这些要点:

The href attribute is repeated in the second a element. This isn’t a mistake—it’s there because without it, Internet Explorer users who navigate to the destination would find that, although the document had moved to the correct position on the screen, the focus will not have shifted. If the user were to tab to the next link, the focus would move to the link immediately after the link the user had selected further up the page, rather than the next link after the point in the page at which the references are included. It’s possible to simply apply an id attribute to another element—for example, <h3 id="refs">References</h3>—and some browsers will allow you to activate a link and jump to that point. However, not all browsers allow this, the notable case being Internet Explorer. That’s why we need the seemingly superfluous second a element as an anchor, which is wrapped around the text inside the h3. The syntax for this simplified (but not IE-friendly) markup is shown below:

href属性在第二个a元素中重复。 这不是一个错误-在那里是因为没有它,导航到目标位置的Internet Explorer用户会发现,尽管文档已移动到屏幕上的正确位置,但是焦点不会移动。 如果用户要跳至下一个链接,则焦点将在用户选择了页面的上一个链接之后立即移至该链接,而不是页面中包含引用的点之后的下一个链接。 可以简单地将id属性应用于另一个元素,例如<h3 id="refs">References</h3> ,某些浏览器将允许您激活链接并跳至该点。 但是,并非所有浏览器都允许这样做,值得注意的是Internet Explorer。 这就是为什么我们需要看似多余的第二个元素作为锚点,并将其包裹 h3内的文本周围 。 下面显示了这种简化的(但不是IE友好的)标记的语法:

<p>You can check the facts by reading the
<a href="#refs">references at the end of this article</a></p>
⋮
<h3 id="refs">References</h3> 

In your own work, you may spot examples that include both a name and id inside the anchor a element. This approach is designed to ensure that the link works in older browsers which may not allow the user to jump from one part of a document to another if the name attribute isn’t present. However, the last of the common browsers that weren’t able to link to a section of a page in this way was Netscape 4, which, thankfully, is now almost completely obsolete. Also, note that in HTML 5 the name attribute has been removed, so it’s a good idea to break the habit of using name.

在您自己的作品中,您可能会发现在元素的锚点中同时包含名称和ID的示例。 此方法旨在确保链接在较旧的浏览器中有效,如果没有name属性,则该链接可能不允许用户从文档的一部分跳到另一部分。 但是,最后无法以这种方式链接到页面部分的常见浏览器是Netscape 4,值得庆幸的是,现在它已几乎完全过时了。 另外,请注意,在HTML 5中, name属性已被删除,因此,最好改掉使用name的习惯。

In addition to links to documents (such as web pages or other document types), the href attribute may specify a different protocol, including:

除了指向文档(例如网页或其他文档类型)的链接之外,href属性还可以指定其他协议,包括:

  • ftp typed as <a href="ftp://someftpserver.com/">Browse the FTP server</a>, which will open a connection to an FTP server

    FTP类型为<a href="ftp://someftpserver.com/">Browse the FTP server</a> ,这将打开到FTP服务器的连接

  • mailto typed as <a href="mailto:mrwhatever@somedomain.com">Email me!</a>, which will trigger an email client to open and create a new message whose To address matches whatever appears after the mailto: protocol (in this case, an email to mrwhatever@somedomain.com)

    mailto键入为<a href="mailto:mrwhatever@somedomain.com">Email me!</a>发送<a href="mailto:mrwhatever@somedomain.com">Email me!</a> ,这将触发电子邮件客户端打开并创建新邮件,该邮件的“收件人地址”与mailto:协议后出现的内容相符(在这种情况下,请发送电子邮件至mrwhatever@somedomain.com)

值 (Value)

This attribute takes as its value the location of the destination document relative to the referencing document, relative to the server root, or in the form of a complete URI containing the http:// protocol, the server name, and the path to the document on that server. It may also contain a reference to the ftp:// or mailto: protocols.

此属性将目标文档相对于参考文档,相对于服务器根目录的位置或包含http://协议,服务器名称和文档路径的完整URI的形式作为其值。在该服务器上。 它还可能包含对ftp://mailto:协议的引用。

翻译自: https://www.sitepoint.com/href-html-attribute/

html中的href属性

html中的href属性_href(HTML属性)相关推荐

  1. php target当前页面,href标签target=_blank属性的妙用

    我们都知道 html 超链接标签 href 属性 target="_blank" 的作用是使打开的链接以新开的窗口形式出现.但是除了直接写在 href 标签里面,你还知道有其他更巧 ...

  2. JavaScript 中BOM及window的相关属性及方法

    概述:BOM (全称bowser object model) 浏览器对象模型,他是用于操作浏览器相关的内容.BOM是一个缺乏规范的东西,为了保证他的规范性产生了一系列的共用对象来解决这个问题.沿用至今 ...

  3. python中属性和类级变量_六、Python类变量和实例变量(类属性和实例属性)

    我们知道,无论是在类中定义的属性还是方法,在类的外部,都无法直接调用它们,因此,我们完全可以把类看做是一个独立的作用域(称为类命名空间),则类属性其实就是定义在类命名空间内的变量(类方法其实就是定义的 ...

  4. DHTML中style的display和visibility属性

    DHTML中style的display和visibility属性 display是隐藏该对象,使该对象不占用页面排版空间. document.all("tr1").style.di ...

  5. python类中的属性分为类属性和实例属性两种_python中类和实例如何绑定属性与方法示例详解...

    前言 python类与实例的方法的调用中觉得云里雾里,思考之后将自己的想法记录下,一来加深自己理解,巩固自己记忆,而来帮助一些想要学习python的朋友理解这门抽象的语言,由于Python是动态语言, ...

  6. JavaScript 中 Object ,Prototype 相关的属性和方法

    1.Objuect 类型 Object 类型是所有对象的基类型,可以用 new 运算符产生一个 Object 类型. 开发者可以通过产生 Object 类型的实例并向其动态添加属性和方法来产生自己需要 ...

  7. 请确保此代码文件中定义的类与“inherits”属性匹配,并且该类扩展的基类(例如Page 或UserControl)是正确的。...

    编译ASP.NET时,提示"请确保此代码文件中定义的类与"inherits"属性匹配,并且该类扩展的基类(例如Page 或UserControl)是正确的.", ...

  8. 如何在Javascript中访问对象的第一个属性?

    本文翻译自:How to access the first property of an object in Javascript? Is there an elegant way to access ...

  9. 一个类的实例是另一个类的属性python_Python中的类属性和实例属性引发的一个坑...

    问题 今天在项目中遇到了个奇怪的问题,实例的一个时间属性并没有根据时间变化而变化,分析之后恍然大悟,总结下分享给大家.大家先看一段代码: import datetime import time cla ...

最新文章

  1. Java NIO 学习笔记 缓冲区补充
  2. UIImageView动画
  3. android开发之-软件设置保存-快速学会使用SharedPreferences篇-实测
  4. 动态规划之状态机模型
  5. Windows 7 下IIS 7.5 结合Zend构建PHP集成开发环境
  6. python bool 转vc int_史上最全的 Python 3 类型转换指南
  7. 【LINQ】Linq to SQL -- Count/Sum/Min/Max/Avg 操作符
  8. mysql fetch field_PHP mysql_fetch_field() 函数
  9. 如何进入服务器文件管理,服务器怎么打开任务管理器
  10. 建议不要使用Android studio的SVN功能
  11. 词法分析flex 语法分析bison
  12. EV: 致新教育萤火虫父母们
  13. Github / Gitlab Actions 中的 cron 格式 和设置方法
  14. 算法(普通算法+大数据)
  15. 第三方支付系统--支付流程
  16. jdk1.8连接数据库sql server2008l异常解决办法
  17. sql语句集合里有集合_学习SQL:集合论
  18. 使用 ffmpeg 命令将视频转图片
  19. 如何正确理解企业文化
  20. MongoDB简单入门篇及其Spring Boot整合

热门文章

  1. 网站建设制作需要多少钱呢?费用是多少?
  2. 如何压缩css代码,在开发中怎么压缩js和css?有哪些办法?
  3. 为什么阿里巴巴强制不要在 foreach 里执行删除操作
  4. RFID之M1卡数据分析
  5. netkeeper代理服务器未响应,使用netkeeper创翼网速慢解决方案(C13)
  6. MIST浏览器不能连接私有链
  7. HTML结构及常用的标签
  8. 大学计算机专业吐槽,大学专业吐槽集锦:分分钟让你感觉“前途无亮”!
  9. [HSI论文阅读] | Deep Feature Extraction and Classification of Hyperspectral Images Based on CNNs
  10. 阿里“小前台、大中台”的解读