自关闭输入标签在 HTML 4 中有效吗?

发布于 2024-09-08 11:13:13 字数 403 浏览 1 评论 0原文

根据 http://www.w3.org/TR/html401 /interact/forms.html#h-17.4,输入元素应以单个 > 结尾,而不是 />。尽管大多数浏览器都可以处理以 /> 结尾的输入元素,但是根据 HTML 语法规则,这样的输入元素有效吗?换句话说,像
这样的元素在 HTML 4 中有效吗?

(这个问题是关于 HTML 而不是 XHTML!!!)

According to http://www.w3.org/TR/html401/interact/forms.html#h-17.4, an input element should end with a single > and not a />. Though that most browsers can handle an input element that ends with />, is such an input element valid according to HTML syntax rules? In other words are elements like <input ... /> and <br /> valid in HTML 4?

(This question is about HTML and not XHTML!!!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

居里长安 2024-09-15 11:13:13

该语法在某些地方有效与XHTML中的含义不同,因此不要使用它们。

在 HTML 4 中 (其中 foo 是定义为 EMPTY 的元素名称)与 含义相同>> 含义相同(尽管几乎没有浏览器正确支持该语法,Emacs-W3 曾经支持,但破坏了与有利于正确呈现所谓的 HTML 兼容 XHTML 1.0 文档的标准)。

因此,这在您可以拥有 > 的地方有效,例如允许您使用 的任何地方,但在其他地方则无效(例如


,它是 的子元素(严格来说)。

与可选开始和结束标记的规则的交互增加了更多的复杂性。在过渡性文档中,这是有效的:

<link …/>
<h1>Hello, world</h1>

并且意味着:

<link>
</head>
<body>
>
<h1>Hello, world</h1>

这种速记语法可能很有用,或者至少可以节省时间,例如:

<title/The quick brown fox/

而不是更详细的:

<title>The quick brown fox</title>

...但是 该语法从未得到很好的支持,并且规范表示应该避免使用它。

The syntax is valid in some places but doesn't mean the same as in XHTML, so don't use them.

In HTML 4 <foo /> (where foo is the name of an element defined as EMPTY) means the same as <foo>> which means the same as <foo>> (although almost no browser supports the syntax correctly, Emacs-W3 used to, but broke compatibility with the standard in favour of rendering so-called HTML compatible XHTML 1.0 documents correctly).

This is, therefore, valid in places where you can have a > such as anywhere you are allowed an <img> but not in other places (such as an <hr> that is a child element of the <body> (in Strict)).

The interaction with the rules for optional start and end tags adds more complication. In a Transitional document, this is valid:

<link …/>
<h1>Hello, world</h1>

and means:

<link>
</head>
<body>
>
<h1>Hello, world</h1>

This shorthand syntax could be useful, or at least a time saver, for things like:

<title/The quick brown fox/

instead of the more verbose:

<title>The quick brown fox</title>

… but the syntax has never been well supported and the specification says it should be avoided.

染年凉城似染瑾 2024-09-15 11:13:13

实际上已解决...根据 W3C HTML 4 验证器,最好不要在 HTML 4 中使用这种编写元素名称的风格:

NET-enabling start-tag requires SHORTTAG YES
<br />
The sequence <FOO /> can be interpreted in at least two different ways, 
depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates 
the tag <FOO (with an implied '>'). However, since many browsers don't interpret it 
this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid 
it completely in pure HTML documents and reserve its use solely for those written in XHTML.

Solved actually... according to W3C HTML 4 validator it's better not to use this style of writing element names in HTML 4:

NET-enabling start-tag requires SHORTTAG YES
<br />
The sequence <FOO /> can be interpreted in at least two different ways, 
depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates 
the tag <FOO (with an implied '>'). However, since many browsers don't interpret it 
this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid 
it completely in pure HTML documents and reserve its use solely for those written in XHTML.
澜川若宁 2024-09-15 11:13:13

来自 HTML 兼容性指南

在尾随 /< 之前包含一个空格空元素的 /code> 和 >,例如


< ;img src="karen.jpg" alt="Karen" />.另外,对空元素使用最小化标记语法,例如
,因为 XML 允许的替代语法

给出许多现有用户代理的结果不确定。

From the HTML Compatibility Guidelines:

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文