class="list" bgcolor="#ffffff" onmouseover="this.bgColor='#FFFDE2';" onmouseout="this.bgColor='#ffffff';"tr里要有这些,一起问了
谢谢~

解决方案 »

  1.   

    这是修改tr对象的属性问题
    直接赋值就好了
    tr.class="list";
    tr.bgcolor="#ffffff";
    tr.onmouseover="this.bgColor='#FFFDE2'";
    tr.onmouseout="this.bgColor='#ffffff'";
      

  2.   

    或者用setAttribute("attribute","attributeValue")方法
    tr.setAttribute("class","list");
    ……
      

  3.   

    这是我自己写的一个表格封装类,送给你啦
    <!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>
        <title>无标题页</title>
        <script language="javascript" type="text/javascript">
        
        function Table()
        {
            this.table=null;    //表格标签
            this.dataBody=null; //数据显示区
            this.templet=null;  //模板行
        }
        Table.prototype.setTable=function(tableID)
        {
            this.table=document.getElementById(tableID);
            if(this.table!=null)
            {
                this.dataBody=this.table.children("tblDataBody");
                
                //取得模板行
                var tbody=this.table.children("tblTemplet");
                this.templet=tbody.rows[0];
                this.templet.style.display="none";  //将模板隐藏
            }
        }
        
        //新增一行
        Table.prototype.NewRow=function(addToTable)
        {
            //深层克隆模板行
            var row=this.templet.cloneNode(true);
            row.style.display="block";  //设置为可见
            this.AddRow(row);   //加到数据显示区中
            return row; //反回该行,以供编辑
        }
        
        //清空表格
        Table.prototype.Clear=function()
        {
            while(this.dataBody.rows.length>0)
            {
                this.dataBody.deleteRow(0);
            }
        }
        
        //删除一行
        Table.prototype.DeleteRow=function(row)
        {
            this.table.deleteRow(row.rowIndex);
        }
        
        //以下标为参数,删除一行
        Table.prototype.DeleteAt=function(index)
        {
            this.dataBody.deleteRow(index);
        }
        
        //将新行添加到数据显示区中
        Table.prototype.AddRow=function(row)
        {
            this.dataBody.appendChild(row);
        }
        
        //取得所有行
        Table.prototype.getRows=function()
        {
            return this.dataBody.rows;
        }
        
        
        var tbl=new Table();
        window.onload=function()
        {
            tbl.setTable("tblList");
        }
        function Test()
        {
            var row=tbl.NewRow(true);
            row.cells["c1"].innerHTML="newC1";
            row.cells["c2"].innerHTML="newC2";
        }
        </script>
    </head>
    <body>
        <input id="Button1" type="button" value="增加一行" onclick="Test()"/>
        <table id="tblList" border="1" style="border-collapse: collapse;" cellpadding="0" cellspacing="0">
            <thead><tr><th>列1</th><th>列2</th></tr></thead>
            
            <!--数据区TBODY,该TBODY为空,ID指定为tblDataBody-->
            <tbody id="tblDataBody">
            </tbody>
            
            <!--模板TBODY,该TBody有且仅有一行,ID指定为tblTemplet-->
            <tbody id="tblTemplet">
                <tr style="cursor:pointer;">
                    <td id="c1">c1</td>
                    <td id="c2">c2</td>
                </tr>
            </tbody>
        </table>
    </body>
    </html>
      

  4.   

    修正一下
    Table.prototype.NewRow=function(addToTable)
    这个函数,可以把addToTable去掉了
    以及var row=tbl.NewRow(true);这里把参数true去掉
      

  5.   

    你只要再在相应的位置上加上
    :trObj.className="样式名";
    就可以了
      

  6.   

    记得设置class不能obj.class="xxx"而应该obj.className="xxx"