为什么 XMLElement 接口不是 Web API 的一部分?
Why XMLElement interface is not part of Web APIs?
在MDN Web APIs Specifications, there are HTMLDocument, XMLDocument, HTMLElement 接口中。因此我也希望看到一个 XMLElement 接口。
但是,未看到 XMLElement 接口。因此,我进行了此查询,以了解该模式停止的原因。
您希望 XMLElement
界面有什么具体行为?
我们只为确实需要特定行为的元素创建新的接口,简单的 XML 元素没有,它们完全被 Element
接口覆盖。
关于您关于 setAttribute
的问题,in HTML the method 将查看定义元素的名称-space,以及它所属的文档。
例如,您可以在 HTML 文档中使用 SVG 等外来元素,它们的属性不会小写。
const svg = document.querySelector("svg");
svg.setAttribute("viewBox", "0 0 1 1");
console.log("is HTMLDocument", document instanceof HTMLDocument);
console.log("has lower case attribute 'viewbox'", svg.hasAttribute("viewbox"));
console.log("has camel case attribute 'viewBox'", svg.hasAttribute("viewBox"));
<svg></svg>
请注意,由于此
或者您可以在 XML 文档中包含 HTML 元素,其中它也不会小写:
const XML_Doc = document.implementation.createDocument(null, "");
const HTML_elem = document.createElement("div");
XML_Doc.append(HTML_elem);
HTML_elem.setAttribute("myAttribute", "");
console.log("is XMLDocument", XML_Doc instanceof XMLDocument);
console.log("is HTMLElement", HTML_elem instanceof HTMLElement);
console.log("has lower case attribute 'myattribute'", HTML_elem.hasAttribute("myattribute"));
console.log("has camel case attribute 'myAttribute'", HTML_elem.hasAttribute("myAttribute"));
使用不同的界面在这里无济于事。
另请注意,XMLDocument 接口存在是因为它曾经具有一些独特的method/properties。它不再存在,但完全删除界面可能对网络不安全,某些网站可能依赖于它。
在MDN Web APIs Specifications, there are HTMLDocument, XMLDocument, HTMLElement 接口中。因此我也希望看到一个 XMLElement 接口。
但是,未看到 XMLElement 接口。因此,我进行了此查询,以了解该模式停止的原因。
您希望 XMLElement
界面有什么具体行为?
我们只为确实需要特定行为的元素创建新的接口,简单的 XML 元素没有,它们完全被 Element
接口覆盖。
关于您关于 setAttribute
的问题,in HTML the method 将查看定义元素的名称-space,以及它所属的文档。
例如,您可以在 HTML 文档中使用 SVG 等外来元素,它们的属性不会小写。
const svg = document.querySelector("svg");
svg.setAttribute("viewBox", "0 0 1 1");
console.log("is HTMLDocument", document instanceof HTMLDocument);
console.log("has lower case attribute 'viewbox'", svg.hasAttribute("viewbox"));
console.log("has camel case attribute 'viewBox'", svg.hasAttribute("viewBox"));
<svg></svg>
请注意,由于此
或者您可以在 XML 文档中包含 HTML 元素,其中它也不会小写:
const XML_Doc = document.implementation.createDocument(null, "");
const HTML_elem = document.createElement("div");
XML_Doc.append(HTML_elem);
HTML_elem.setAttribute("myAttribute", "");
console.log("is XMLDocument", XML_Doc instanceof XMLDocument);
console.log("is HTMLElement", HTML_elem instanceof HTMLElement);
console.log("has lower case attribute 'myattribute'", HTML_elem.hasAttribute("myattribute"));
console.log("has camel case attribute 'myAttribute'", HTML_elem.hasAttribute("myAttribute"));
使用不同的界面在这里无济于事。
另请注意,XMLDocument 接口存在是因为它曾经具有一些独特的method/properties。它不再存在,但完全删除界面可能对网络不安全,某些网站可能依赖于它。