插入元素的方法,注意的是:
list为child的时候才能够插入到元素中
var newChild = document.createElement('A');
newChild.appendChild(document.createTextNode('chorme'));
newChild.setAttribute('href', 'http://www.baidu.com');
var list =document.getElementById('msie');
list.insertBefore(newChild, list.lastChild);
var brChild = document.createElement('BR');
list.insertBefore(brChild, list.lastChild);
This is my HTML page. <br>
<div id&#61;&#39;firefox&#39; ></div>
<hr/>
<div>
<ul>
<li id&#61;&#39;firefoxListItem&#39; title&#61;"firefox">
<a href&#61;"#" title&#61;"get Firefox" id&#61;"firefox">Firefox 2.0</a>
</li>
<li>
<a href&#61;"#" title&#61;"getMicrsoft Inter" id&#61;&#39;msie&#39;>ie11</a>
</li>
<li>
<a href&#61;"#" title&#61;"check out safari" id&#61;&#39;safari&#39;>safari</a>
</li>
<li>
<a href&#61;"#" title&#61;"getOpera" id&#61;&#39;Opera&#39;>Opera</a>
</li>
</ul>
</div>
- Firefox 2.0
- chorme
ie11 - safari
- Opera
来自为知笔记(Wiz)