创建节点
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>创建节点</title>
<style type="text/css"></style>
<script type="text/javascript">
window.onload=function()
{
var oTxt1=document.getElementById('txt1');
var oBtn1=document.getElementById('btn1');
var oUl=document.getElementById('ul1');
oBtn1.onclick=function()
{
var oLi=document.createElement('li');
oLi.innerHTML=oTxt1.value;
if(oUl.childNodes.length==0)
{
oUl.appendChild(oLi);
}
else
{
oUl.insertBefore(oLi,oUl.childNodes[0]);
//oUl.insert
}
}
}
</script>
</head>
<body>
<input type="text" id="txt1" />
<input id="btn1" type="button" value="添加" />
<ul id="ul1"></ul>
</body>
</html>
浙公网安备 33010602011771号