动态表格展示出来以后也就是静态的啦,可以根据ID取值的,如果没有ID,输出的时候就给一个,看一下前台代码就知道了,当然,这个功能要用JS实现了

解决方案 »

  1.   

    <!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=gb2312" /> 
    <title>表格 </title> 
    <script type="text/javascript"> 
    function copy() {
    var obj = document.activeElement;
    document.getElementById(parseInt(obj.id)+1).value = document.getElementById(parseInt(obj.id)-1).value;
    }
    var i = 0;
    function createTable() 

        var tb = document.getElementById("tab").tBodies[0]; 
        var row = tb.insertRow(0); 
        var cell = row.insertCell(0); 
        var ipt1 = document.createElement("input");
        ipt1.id = i++;
        ipt1.type = "text"; 
        cell.appendChild(ipt1); 
        var ipt2 = document.createElement("input"); 
        ipt2.id = i++;
        ipt2.type = "button"; 
        ipt2.value = "COPY";
        ipt2.onclick = function() { copy(); };
        cell = row.insertCell(1); 
        cell.appendChild(ipt2); 
        cell = row.insertCell(2); 
        ipt1 = document.createElement("input"); 
        ipt1.id = i++;
        ipt1.type = "text"; 
        cell.appendChild(ipt1);

    </script> 
    </head> 
    <body> 
    <button onclick="createTable()">添加行 </button> 
    <table border="1" id="tab"> 
    </table> 
    </body> 
    </html> 
      

  2.   

     ipt2.attachEvent("onclick",
    function(){
    var tr=ipt2.parentNode.parentNode;
    tr.cells[2].childNodes[0].value =tr.cells[0].childNodes[0].value;
    }
       );