关于createElement、appendChild和insertBefore的用法
来源:互联网 发布:单片机usb转串口驱动 编辑:程序博客网 时间:2024/05/14 01:04
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testCreateElement.aspx.cs" Inherits="grid.testCreateElement" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<style type="text/css">
div{
border-style:solid;
border-width:1px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="parentControl" >
<a href="#">aaaaaaaaaaa</a>
</div>
</form>
<script type="text/javascript" language="javascript">
//createElement()的用法
var parentControl=document.getElementById("parentControl");
//添加select
var selectC = document.createElement("select");
selectC.options[1] = new Option("加载1","1");
selectC.options[2]=new Option("加载2","2");
selectC.options[2].setAttribute("selected","selected"); //使其中一行显示
selectC.size=1; //显示的行数
parentControl.appendChild(selectC);
//添加Button
var btnC=document.createElement("input");
btnC.type="button";
//或者
//btnC.value="按钮"; 可见,setAttribute("value","按钮");可以在一控件中加入相应的属性或按钮的事件
btnC.setAttribute("value","按钮");
parentControl.appendChild(btnC);
// 下面来看 appendChild(btnC);与insertBefore()的用法;
var btnA=document.createElement("input");
btnA.setAttribute("type","button");
btnA.setAttribute("value","btnA");
//parentControl.appendChild(btnA);
//或者,这两个没什么区别
//parentControl.insertBefore(btnA,null);
parentControl.insertBefore(btnA,parentControl.childNodes[3]); //而这个语句,可以将btnAr按钮插入到parentControl中的任何位置
//总结:insertBefore可以插入到子结点集的任何位置,但appendChild只能插入到子结点集的末尾。
</script>
<select>
<option>ddd</option>
<option >fff</option>
<option selected="selected">kk</option>
</select>
</body>
</html>
- 关于createElement、appendChild和insertBefore的用法
- document.createElement()用法中appendChild()、 insertBefore()的区别
- appendChild、removeChild、insertBefore、createElement、cloneNode的区别;
- JS 中的appendChild和createElement的用法
- JS:appendChild()和insertBefore()
- JS appendChild和insertBefore
- appendChild /insertBefore 的错误
- 【JS--DOM-节点操作2】--createElement()、appendChild()、insertBefore()、自定义的insertAfter()
- appendChild与insertBefore用法比较
- js中AppendChild与insertBefore的用法详细解析
- js createElement appendChild createTextNode用法
- insertBefore()方法 和 appendChild() 方法
- js:appendChild、insertBefore和insertAfter
- appendChild()和insertBefore()方法插入元素的区别
- 引用 appendChild与insertBefore用法比较
- createElement appendChild
- appendChild和insertBefore ,append和appendTo
- JavaScript之appendChild、insertBefore和insertAfter
- 远程通讯实例(RMI)
- c语言代码的优化
- java的property配置文件的用法
- 密码 报文分析 规约对比(97-07)
- 中村勇吾作品:弹性波浪
- 关于createElement、appendChild和insertBefore的用法
- 关于pcb封装制作的注意事项
- Arable Area
- 2011/3/30
- Liferay:语言配置文件和portal-ext配置文件的编辑(乱码回避)
- 关于ARM的C语言优化
- 中国软件界为何出不了大师?
- SVN
- 美国卷烟纸改进卷烟制品香味