我可以帮您翻译成中文。这段文字是关于编程的,作者对如何在文档中插入HTML标签感到困惑,想知道哪种方法更实用和高效。下面是需要翻译的内容:
我对以下代码风格感到困惑。我想知道在文档中插入HTML标签的最实用和高效的方法是哪一个。
Javascript:
document.getElementById('demoId').innerHTML='<div>hello world and <a>click me</a> also</div>';
或者
var itd=document.createElement('div'),
ita=document.createElement('a'),
idt=document.createTextNode('hello world');
iat=document.createTextNode('click me');
idn=document.createTextNode('also');
ita.appendChild(iat);
itd.appendChild(idt);
itd.appendChild(ita);
itd.appendChild(idn)
docuemtn.getElementById('demoId').appendChild(itd);
哪种方法最快且最好?