因此,如果我们要将LI附加到UL,我们应该这样做:
var list = document.createElement('li');
var ulist = document.createElement('ul');
ulist.appendChild(list);
如果我创建跨度该怎么办?
var list = document.createElement('li');
var ulist = document.createElement('ul);
var span = document.createElement('span');
span.appendChild(ulist);
ulist.appendChild(list);
答案 0 :(得分:1)
这就是您要做的事情,是的(错别字除外-缺少结束'
),除外,span
元素不能包含ul
元素。 span
的内容模型为phrasing content,但是ul
仅可用于预期flow content的地方。
答案 1 :(得分:0)
ul后面缺少引号,但您的代码正确。
在后面的代码中,您要将<li>
附加到<ul>
,并将相同的<ul>
附加到<span>
。您可能需要将所有这些附加到正文以使其出现。请参见下面的示例:
const list = document.createElement('li');
const ulist = document.createElement('ul');
const span = document.createElement('span');
span.appendChild(ulist);
ulist.appendChild(list);
document.body.appendChild(span);