<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1<---strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="cache-control" content="max-age=5"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
        </script>
<script language="javascript">
 function addObj() {
var input=createDiv();
        document.getElementById("div1").appendChild(input);
    } function createDiv(){

var td=Math.floor(Math.random()*100000);

        var input = document.createElement('div');
var ind = document.createElement('input');
ind.type="text";
        input.style.border="solid 1px #666";
input.id=td; var but = document.createElement('input');
but.type="button";
but.value="XIAFANG";
but.onclick=function(){
var targetE=document.getElementById(td);

var newEl=createDiv();
insertAfter(newEl, targetE);
}; var but1 = document.createElement('input');
but1.type="button";
but1.value="SHANGFANG";
but1.onclick=function(){
var ol=document.getElementById(td);

var newChild=createDiv();
document.getElementById("div1").prependChild1(newChild,ol);

}; var but3 = document.createElement('input');
but3.type="button";
but3.value="SC";
but3.onclick=function(){
var s=document.getElementById(td);
document.getElementById("div1").removeChild(s);
};
var but2 = document.createElement('input');
but2.type="button";
but2.value="XS";
but2.onclick=function(){
var s=document.getElementById(td).firstChild.value;
alert(s);};

input.appendChild(ind);
input.appendChild(but1);
input.appendChild(but);
input.appendChild(but2);
input.appendChild(but3);
return input;
}//这个是添加元素到上边 
function prependChild(parent,newChild){
    if(parent.firstChild){
        parent.insertBefore(newChild,parent.firstChild);
    } else {
        parent.appendChild(newChild);
    }
    
    return parent;
}//添加到某个元素的上边
function prependChild(parent,newChild,ol){
    
        parent.insertBefore(newChild,ol);
   
    
    return parent;
}
Element.prototype.prependChild1=function(newChild,ol){ this.insertBefore(newChild,ol);
   
    
    
}function insertAfter(newEl, targetEl)
{
      var parentEl = targetEl.parentNode;      if(parentEl.lastChild == targetEl)
      {
           parentEl.appendChild(newEl);
      }else
      {
           parentEl.insertBefore(newEl,targetEl.nextSibling);
      }            
}
</script>
</head>
  <body>
  <input name="dddd" value="tianjia" type="button" onclick="addObj()"/>
<div id="div1"></div>
  </body>
</html>