<table id="printTable" class="inputNeed"> 
<tr id="printTr" class="trNeed"> 
<td> 
<td> 
<tr> 
</table> js代码: 
var pri = document.getElementById("printTable").cloneNode(true);//克隆节点。 现在我想改变克隆节点(pri)里面的tr的css样式,请问如何实现?

解决方案 »

  1.   


    <style>
    .new{background:red;}
    </style>
    <script language="JavaScript"> 
    window.onload=function () {
    var pri = document.getElementById("printTable").cloneNode(true);
    var tr = pri.getElementsByTagName("tr")[0].className="new";
    document.body.appendChild(pri);

    </script> <table id="printTable" class="inputNeed"> 
    <tr id="printTr" class="trNeed"> 
    <td>xxxx<td> 
    <tr></table>
      

  2.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style type="text/css">
    .mytr{
    background-color:red;
    }
    </style>
    <script language="javascript">
    window.onload = function(){
    var pri = document.getElementById("printTable").cloneNode(true);
                    //注释范围内的
    for(var i=0;i<pri.children.length;i++){
    pri.children[i].setAttribute("className","mytr");
    }
                    //
    document.body.appendChild(pri);
    }
    </script>
    </head><body>
    <table width="100" height="100" border="1" id="printTable"> 
    <tr> <td>1</td> </tr>
    <tr> <td>1</td> </tr>
    <tr> <td>1</td> </tr>
    </table> 
    </body>
    </html>