簡體   English   中英

在dom中,html元素和片段之間的功能區別是什么?

[英]in dom, what is functional difference between an html element and a fragment?

已經發現片段在構建動態html時非常有用-就像使用一袋html元素以及放置后該袋本身會溶解-很好。

我假設html元素和片段的方法相同,但是我認為這是不正確的。

似乎片段具有節點方法appendChild()等-但沒有更復雜的html元素方法,例如getElementsByTagName()

這個評估正確嗎? 還是我以一種新的方式射擊自己的腳?

DocumentFragment擴展了Node接口,並定義為

interface DocumentFragment : Node {
};

HTMLElementElement擴展而來,其接口定義為

interface HTMLElement : Element {
    attribute DOMString id;
    attribute DOMString title;
    attribute DOMString lang;
    attribute DOMString dir;
    attribute DOMString className;
};

Element又擴展了Node接口。 它包含方法getElementsByTagName以及其他幾種方法,

interface Element : Node {
    ...
    NodeList getElementsByTagName(in DOMString name);
    ..
};

簡而言之,為回答您的問題,文檔片段和html元素都共享node接口

DocumentFragment接口擴展了Node接口 ,從而提供了用於插入和克隆元素的方法,但不提供 getElementsByTagName()等方法。 這些可以在Document界面 (也擴展Node )中找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM