元素结束标签中的属性?

发布于 2024-09-17 01:23:33 字数 265 浏览 5 评论 0原文

执行以下操作是否被认为有效:

<li>stuff</li class="randomlengthclassname">
<li>stuff</li class="shortclassname">
<li>stuff</li class="reallyreallylongarseclassname">

或者属性 have 是否位于开始标记中?

Is it considered valid to do the following:

<li>stuff</li class="randomlengthclassname">
<li>stuff</li class="shortclassname">
<li>stuff</li class="reallyreallylongarseclassname">

or do the attribute have to be in the opening tag?

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

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

发布评论

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

评论(5

甜点 2024-09-24 01:23:33

不,不是。您必须在开始标记中使用属性。

w3c 验证器中运行 test 导致此错误:

名称起始字符无效:此处仅允许使用 S 分隔符和 TAGC

其中 S 分隔符和 TAGC 是:

    S is "whitespace" separator

    [5] s =

        SPACE | (32) space
        RE | (13) CR
        RS | (10) LF
        SEPCHAR (9) HT

            -- http://xml.coverpages.org/sgmlsyn/sgmlsyn.htm#C6.2.1

    TAGC    ">"

            -- http://www.w3.org/TR/sgml.l

No it isn't. You must use attributes in the opening tag.

Running <a>test</a href="tst.html"> in w3c validator results in this error:

name start character invalid: only S separators and TAGC allowed here

Where S separators and TAGC are:

    S is "whitespace" separator

    [5] s =

        SPACE | (32) space
        RE | (13) CR
        RS | (10) LF
        SEPCHAR (9) HT

            -- http://xml.coverpages.org/sgmlsyn/sgmlsyn.htm#C6.2.1

    TAGC    ">"

            -- http://www.w3.org/TR/sgml.l
天赋异禀 2024-09-24 01:23:33

这是无效有效的,并且所有属性确实都必须在开始标记中定义。

This is not valid, and all attributes must be defined in the opening tag, indeed.

梦冥 2024-09-24 01:23:33

该属性必须位于开始标记中。您提供的代码可能无法工作。

The attribute has to be in the opening tag. The code which you have presented probably wouldn't work.

伴随着你 2024-09-24 01:23:33

属性应出现在元素的 start 标记中。引用W3C:关于 SGML 和 HTML 属性

...属性/值对出现在最后的“>”之前元素的开始标记。任意数量的(合法)属性值对(以空格分隔)可以出现在元素的开始标记中。它们可以以任何顺序出现。

Attributes should appear in the element's start tag. Quoting the W3C: On SGML and HTML Attributes:

... Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag. They may appear in any order.

谁人与我共长歌 2024-09-24 01:23:33

结束标记不得包含属性。
但在 HTML4 中,您可以省略结束 LI

<!ELEMENT LI - O (%flow;)*             -- list item -->
<!ATTLIST LI
  %attrs;                              -- %coreattrs, %i18n, %events --
  >

Start tag: required, End tag: optional

在 XHTML 中,您可能不会。

Closing tags may not contain attributes.
But in HTML4 you may omit the closing LI:

<!ELEMENT LI - O (%flow;)*             -- list item -->
<!ATTLIST LI
  %attrs;                              -- %coreattrs, %i18n, %events --
  >

Start tag: required, End tag: optional

In XHTML, you may not.

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