求一用js动态增加行,并能让行上行移动置底.置顶功能..

解决方案 »

  1.   


    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
            <script language="javascript">
                
                function addInput(){
                    var div=document.getElementById("inputDiv")
                    var input="<input type=text ><input type=button onclick=addInput() value=\"+\">"
                    div.innerHTML+=input;
                    var br=document.createElement("br");
                    div.appendChild(br);
                }
              
                    window.onload=function(){
                     
                    }
                        </script>
        </head>
        <body>
            <div id="inputDiv"><input type="text" ID="Text1" NAME="Text1"/><input type="button" onclick="addInput()" value="+" ID="Button1" NAME="Button1"></input></br></div>
            <div></div>
        </body>
    </html>
      

  2.   

    置顶是这个意思么<html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
            <script language="javascript">
                var id=1;
                function addInput(){
                    var div=document.getElementById("inputDiv")
                    var input="<div id=div"+id+"><input type=text >"+id+"<input type=button onclick=addInput() value=\"+\"><input id=a_"+id+" type=button value=\"置顶\" onclick=gotop(this.id)></br></div>"
                    id++;
                    div.innerHTML+=input;
                }
              function gotop(id){
               var div=document.getElementById("inputDiv");
               var divid=id.split("_")[1];
               var deldiv=document.getElementById("div"+divid);
               var innerhtml=deldiv.innerHTML;
               var firstdiv=document.createElement("div");
               firstdiv.innerHTML=innerhtml;
               firstdiv.id="div"+divid;
               div.removeChild(deldiv);
               div.insertBefore(firstdiv,div.childNodes[0]);
               id--;          }
                    window.onload=function(){
                     
                    }
                        </script>
        </head>
        <body>
            <div id="inputDiv"><input type="text" ID="Text1" NAME="Text1"/>0<input type="button" onclick="addInput()" value="+" ID="Button1" NAME="Button1"></input><input id=a_"+id+" type=button value="置顶" onclick=gotop(this.id) NAME=a_0></br></div>
            <div></div>
        </body>
    </html>
      

  3.   

    如果是,全部代码如下<html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
            <script language="javascript">
                var id=1;
                function addInput(){
                    var div=document.getElementById("inputDiv")
                    var input="<div id=div"+id+"><input type=text >"+id+"<input type=button onclick=addInput() value=\"+\"><input id=a_"+id+" type=button value=\"置顶\" onclick=gotop(this.id)><input id=b_"+id+" type=button value=\"置底\" onclick=gobtom(this.id)></br></div>"
                    id++;
                    div.innerHTML+=input;
                }
              function gotop(id){
               var div=document.getElementById("inputDiv");
               var divid=id.split("_")[1];
               var deldiv=document.getElementById("div"+divid);
               var innerhtml=deldiv.innerHTML;
               var firstdiv=document.createElement("div");
               firstdiv.innerHTML=innerhtml;
               firstdiv.id="div"+divid;
               div.removeChild(deldiv);
               div.insertBefore(firstdiv,div.childNodes[0]);
               id--;          }
              function gobtom(id){
              var div=document.getElementById("inputDiv");
               var divid=id.split("_")[1];
               var deldiv=document.getElementById("div"+divid);
               var innerhtml=deldiv.innerHTML;
               var firstdiv=document.createElement("div");
               firstdiv.innerHTML=innerhtml;
               firstdiv.id="div"+divid;
               div.removeChild(deldiv);
               div.appendChild(firstdiv);
               id--;
              }
              
                    window.onload=function(){
                     
                    }
                        </script>
        </head>
        <body>
            <div id="inputDiv"><input type="text" ID="Text1" NAME="Text1"/>0<input type="button" onclick="addInput()" value="+" ID="Button1" NAME="Button1"></input><input id=a_"+id+" type=button value="置顶" onclick=gotop(this.id) ><input id=b_0 type=button value="置底" onclick=gobtom(this.id) ></br></div>
            <div></div>
        </body>
    </html>