gpt4 book ai didi

html - 为什么不是由不正确的 html 标记引起的错误?

转载 作者:太空宇宙 更新时间:2023-11-04 14:26:19 26 4
gpt4 key购买 nike

在 HTML 规范中有一个概念叫做自定义元素。这些元素的名称应该遵循一个明确的表达式。但是,然而,在浏览器中打开编辑器后,我们可以安全地编写不遵循这些规则的元素,或者简单地创建一个包含不遵循此规则的元素的简单页面。例如,<redcar> </redcar> .为什么这是允许的并且不会导致任何错误?毕竟,如果我们这样写:<~hello> </~hello>那么开始标签将被视为文本,结束标签将被注释掉。在任何情况下,您都需要能够解释此行为的特定链接。

A valid custom element name is a sequence of characters name that meets all of the following requirements:

  • name must match the PotentialCustomElementName production:

PotentialCustomElementName ::= [a-z] (PCENChar)* '-' (PCENChar)*

PCENChar ::= "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

This uses the EBNF notation from the XML specification. [XML]

  • name must not be any of the following:
    • annotation-xml
    • color-profile
    • font-face
    • font-face-src
    • font-face-uri
    • font-face-format
    • font-face-name
    • missing-glyph

最佳答案

不清楚您认为什么是错误

HTML 解析主要面向 never throw 原则,并会尝试将所有内容转换为有效的内容。

在您的特定情况下,您创建的是 HTMLUnknownElement ,这遵循规范:

The element interface for an element with name name in the HTML namespace is determined as follows:

  1. If name is applet, bgsound, blink, isindex, keygen, multicol, nextid, or spacer, then return HTMLUnknownElement.

  2. If name is acronym, basefont, big, center, nobr, noembed, noframes, plaintext, rb, rtc, strike, or tt, then return HTMLElement.

  3. If name is listing or xmp, then return HTMLPreElement.

  4. Otherwise, if this specification defines an interface appropriate for the element type corresponding to the local name name, then return that interface.

  5. If other applicable specifications define an appropriate interface for name, then return the interface they define.

  6. If name is a valid custom element name, then return HTMLElement.

  7. Return HTMLUnknownElement.


<redcar></redcar>你一直走到第 7 号子弹。

关于html - 为什么不是由不正确的 html 标记引起的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51183241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com