空href是否有效? [英] Is an empty href valid?

查看:104
本文介绍了空href是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < a href参考资料您可以参阅本文在developerWorks全球站点上的英文原文。 =class =arrow>< / a> 

这是否被视为锚标记有效?



由于没有href值,它显示在我们的一些链接检查器报告中已损坏。

解决方案

虽然这个问题已经得到解答( tl; dr:是的,一个空的 href 值是有效的) ,现有的答案都没有引用相关的规范。



一个空字符串不能是一个URI。然而, href 属性不仅将URI作为值,还包含URI引用。一个空字符串可能是一个URI引用。 HTML 4.01 HTML 4.01 使用 RFC 2396 ,在 4.2。相同文档引用(大胆强调我的):


不包含URI的URI引用是对当前文件。换句话说,文档中的空白URI引用被解释为对该文档开头的引用,并且仅包含片段标识符的引用是对该文档的标识片段的引用。 / p>

RFC 2396被 RFC 3986 (目前 IETF的URI标准),其中基本上说相同

HTML5



HTML5 使用 可能被空格包围的有效URL 有效网址 W3C的网址规范,该网址已停用。 WHATWG的URL标准应该用来代替(参见上一节)。 HTML 5.1

HTML 5.1 使用 可能被空格包围的有效网址 有效URL WHATWG的网址标准<​​/ strong>(请参阅下一节)。

WHATWG HTML



WHATWG的HTML 使用 可能被sp包围的有效网址aces )定义 有效的URL字符串 来自 WHATWG的网址标准<​​/ strong>,它表示它可以是 relative-URL-with-fragment string ,它必须至少是 relative-URL string ,它可以是 path-relative-scheme-less-URL string ,它是 路径相对URL字符串 , t从一个方案字符串开始,后面跟着,其定义如下(大胆强调我的):


路径相对URL字符串必须为或更多URL-p由U + 002F(/)彼此分开,并且不以U + 002F(/)开始。



One of our web developers uses the following html as a placeholder for styling a drop down list.

<a href="" class="arrow"></a>

Is this considered anchor tag valid?

Since there is no href value, it shows up as broken on some of our link checker reports.

解决方案

Although this question is already answered (tl;dr: yes, an empty href value is valid), none of the existing answers references the relevant specifications.

An empty string can’t be a URI. However, the href attribute doesn’t only take URIs as value, but also URI references. An empty string may be a URI reference.

HTML 4.01

HTML 4.01 uses RFC 2396, where it says in section 4.2. Same-document References (bold emphasis mine):

A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document.

RFC 2396 is obsoleted by RFC 3986 (which is currently IETF’s URI standard), which essentially says the same.

HTML5

HTML5 uses (valid URL potentially surrounded by spacesvalid URL) W3C’s URL spec, which has been discontinued. WHATWG’s URL Standard should be used instead (see the last section).

HTML 5.1

HTML 5.1 uses (valid URL potentially surrounded by spacesvalid URL) WHATWG’s URL Standard (see the next section).

WHATWG HTML

WHATWG’s HTML uses (valid URL potentially surrounded by spaces) the definition of valid URL string from WHATWG’s URL Standard, where it says that it can be a relative-URL-with-fragment string, which must at least be a relative-URL string, which can be a path-relative-scheme-less-URL string, which is a path-relative-URL string that doesn’t start with a scheme string followed by :, and its definition says (bold emphasis mine):

A path-relative-URL string must be zero or more URL-path-segment strings, separated from each other by U+002F (/), and not start with U+002F (/).

这篇关于空href是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆