js 动态绑定tr、td样式和事件

来源:互联网 发布:看最新电影的软件 编辑:程序博客网 时间:2024/06/05 06:39

1、在使用dwrUtil时

DWRUtil.removeAllRows('lines'); //清除所有“lines”里的记录

var cellFuncs = [
     function(data) {
      return data.replyDate;
     } ];
   DWRUtil.addRows(
       'lines',
       tempList,
       cellFuncs,
       {
        rowCreator : function(options) {
         var row = document.createElement("tr");

//鼠标移动到行上面,背景色和行高改变

row.onmouseover = function(){this.style.backgroundColor='#DEDFDE';this.style.height='26';}
row.onmouseout = function(){this.style.backgroundColor='#ffffff';this.style.height='25';}

//设定行的其他样式
row.setAttribute("height","25" );
row.setAttribute("bgcolor","#ffffff" );
row.setAttribute("align","center" );
row.setAttribute("style","" );
row.style.backgroundColor = "#ffffff";
         return row;
        },

        cellCreator : function(options) {
         var td = document.createElement("td");
         var index = options.cellNum;
         if (index == 0) {
          td.height = "25";
         }
         return td;
        },
        escapeHtml :false
       });

2、var row = document.getElementById('foots').insertRow(0);
   var col = row.insertCell(0);
   col.setAttribute("height","35" );
   col.setAttribute("align","center" );
   col.innerHTML = "ttttttttttttttttttt";
   col = row.insertCell(1);
   col.setAttribute("align","right" );
   col.innerHTML = "kkkkkkkkkkkkkkk";

原创粉丝点击