<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
</head>
<body>
<ul id="ul">
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>55</li>
</ul>
<input type="button" value="按钮" id="btn1">
<input type="text" id="tex1">
<script>
window.onload=function(){
var oUl=document.getElementById('ul');
var aLi=document.getElementsByTagName('li');
var oTex=document.getElementById('tex1');
var oBtn=document.getElementById('btn1');
oBtn.onclick=function(){
var oLi=document.createElement('li');
oLi.innerHTML=oTex.value;
if(aLi.length==0){
oUl.appendChild(oLi);
}else{
oUl.insertBefore(oLi,aLi[0]); //insertBefore('插入内容','在谁之前插入')
}
}
}
</script>
</body>
</html>