js insertBefore
2014-05-08 18:08
225 查看
<select id="city" size="4" style="width:50px"> <option id="hn">湖南</option> <option id="hb">湖北</option> </select> <script type="text/javascript"> /*创建"新元素",插入到"湖南"元素之前 var newOptionElement = document.createElement("option"); newOptionElement.setAttribute("id","new"); newOptionElement.innerHTML = "新元素"; var cityElement = document.getElementById("city"); var hnElement = document.getElementById("hn"); cityElement.insertBefore(newOptionElement,hnElement); //新元素 */ //创建"新元素",插入到"湖南"元素之后 var newOptionElement = document.createElement("option"); newOptionElement.setAttribute("id","new"); newOptionElement.innerHTML = "新元素"; var cityElement = document.getElementById("city"); var hnElement = document.getElementById("hn"); //兄弟节点 nextSibling cityElement.insertBefore(newOptionElement,hnElement.nextSibling); </script>
相关文章推荐
- js在指定位置增加节点函数insertBefore()用法实例
- js insertBefore insertAfter appendChild
- js AppendChild与insertBefore用法详细对比
- js AppendChild与insertBefore用法详细对比
- JS(JavaScript)插入节点的方法appendChild与insertBefore
- js中AppendChild与insertBefore的用法详细解析
- js和jq的insert/append/after/before添加节点和文本
- js在指定位置增加节点函数insertBefore()用法实例
- 初学js插入节点appendChild insertBefore使用方法
- js节点内部插入元素的方法appendChild() insertBefore()
- js中AppendChild与insertBefore的用法详细解析
- Raphael.js API之Element.id,Element.insertAfter(),Element.insertBefore(),Element.hide(),Paper.clear(),
- js insertBefore方法
- JS insertBefore
- js 动态创建并插入元素 insertBefore insertAfter
- 初学js插入节点appendChild insertBefore使用方法
- 点滴积累【JS】---JS小功能(createElement和insertBefore添加div下面的节点)
- 初学js插入节点appendChild insertBefore使用方法
- js:插入节点appendChild insertBefore使用方法
- js插入节点appendChild和insertBefore