[英]Creating <li> with JavaScript in an XUL Application
I try to create some li elements in my XUL Application. 我尝试在XUL应用程序中创建一些li元素。 Theres only the text of the elements shown, but no list typical bullets and linebreaks.
仅显示元素的文本,但未列出典型的项目符号和换行符。
Example: 例:
Heres the JS Code I use to create the list: 这是我用来创建列表的JS代码:
var li = document.createElement('html:li');
var txt = document.createTextNode("only shown as simple text");
li.appendChild(txt);
document.getElementById('someList').appendChild(li);
HTML: HTML:
<html:ul id="someList">
<html:li>this is shown in correct list style</html:li>
</html:ul>
I tried 'html:li' and also 'li' but nothing worked. 我尝试了“ html:li”,也尝试了“ li”,但没有任何效果。
Any suggestions? 有什么建议么?
Ok, I figured it out by displaying the reference of the created elements with an alert box... 好的,我通过显示带有警报框的已创建元素的引用来解决这个问题。
If you call createElement the XUL Namespace is used. 如果调用createElement,则使用XUL命名空间。 html:foo has no effect.
html:foo无效。 If you want to create an element in a different namespace then the one of XUL you have to use
如果要在其他名称空间中创建元素,则必须使用XUL之一
createElementNS(namespaceURI, qualifiedName)
So the following code works: 因此,以下代码有效:
var htmlns = "http://www.w3.org/1999/xhtml";
var li = document.createElementNS(htmlns, "li");
var txt = document.createTextNode("text");
li.appendChild(tst);
document.getElementById('someList').appendChild(li);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.