XUL button doesn't appear

廉价感情. 提交于 2019-12-06 00:18:46

document.createElement() doesn't accept qualified names. The "xul:button" string you pass makes it create an element called "xul:button" (== its localName), not a XUL "button" element.

On the other hand when parsing XML, <xul:button> is parsed as a qualified name: the parser searches for namespace corresponding to the xul prefix (from a xmlns:xul="" definition in one of the parent elements) and creates the "button" element in the namespace it found.

The note about not conforming to the DOM spec for XUL and (X)HTML means that you can use regular document.createElement("buttton") to create elements in the XUL or HTML namespace in a XUL or HTML document, correspondingly.

Or you could go the hard way and use:

var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
document.createElementNS(XUL_NS, "button")

or even with the qualified name, not that there's any reason to do that:

document.createElementNS(XUL_NS, "xul:button")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!