为什么 Elm.embed 只接受 div?

Why does Elm.embed only accept divs?

如果您尝试将 Elm.embeddiv 以外的元素一起使用,则会出现此错误:

Elm.node must be given a DIV, not a BODY.

我可以在源代码中看到 this fairly explicitly。我想了解 为什么 存在此限制。例如,为什么我无法将 Elm 嵌入我的 body 标签中?

当您使用 Elm.embed 时,您说的是 "I'm giving full control over the contents of this element to this Elm module"。尝试将其嵌入 body 与使用 Elm.fullscreen 相同(other ways 到 运行 一个 Elm 应用程序之一)。

至于为什么你不能嵌入任何其他标签(比如 <span><p> 标签),我的猜测是它只是为了在语义上正确并避免任何奇怪的行为. <div> 只是一个 "defines a section in a document" 的块元素。 <span> 标签具有相似的语义 ("defines a section in a document"),但它不是块元素(将此 Elm 模块显示为内联元素意味着什么?)。 <p> 标签是块元素,但用于保存一段文本。如果您尝试嵌入 <canvas><iframe> 元素,甚至会发生什么?您只需确保嵌入应用程序的元素是 div.

即可避免所有这些情况