当前位置: 代码迷 >> JavaScript >> javascript<tr>有关问题,求大神指导~
  详细解决方案

javascript<tr>有关问题,求大神指导~

热度:135   发布时间:2012-10-13 11:38:17.0
javascript<tr>问题,求大神指导~~~!
tbAdd()这个函数是向dest_tb表中加入数据。
我的问题是我想让加入的数据所在行在鼠标移入的时候背景变色,移出时候背景便会原色。
可能会跟onMouseOver 相关,这样的代码如何在javascript: tbAdd()中实现,如何设置函数中row 的属性。
row.innerHTML +='< onMouseOver = "test(this);" >'; 
row.onMouseOver = "test(this);" 
类似这种的

JScript code

      function tbAdd(data_scroll,data_name,data_kind,data_qualit,data_dest,data_total,data_price,data_least,data_time,data_urlID){ 
           var tb = document.getElementById("dest_tb");
           rowIndex = tb.rows.length;
           var row = tb.insertRow(rowIndex);
           
           if(data_scroll%2==0)
                row.bgColor="#cccccc"
                
           var scroll = row.insertCell(0);
           scroll.width="50px";
           scroll.height="40px";
           if(data_urlID.length!=0)
                scroll.innerHTML = data_scroll;
           else
                scroll.innerHTML = "";
           scroll.style.fontSize ="14px";
           scroll.align="center";
           var name = row.insertCell(1);
           name.width="150px";
           name.innerHTML = data_name;
           name.style.fontSize ="14px";
           name.align="center";
           var kind = row.insertCell(2);
           kind.width="80px";
           kind.innerHTML = data_kind;
           kind.style.fontSize ="14px";
           kind.align="center";
           var qualit = row.insertCell(3);
           qualit.width="110px";
           qualit.innerHTML = data_qualit;
           qualit.style.fontSize ="14px";
           qualit.align="center";
           var dest = row.insertCell(4);
           dest.width="160px";
           dest.innerHTML = data_dest;
           dest.style.fontSize ="14px";
           dest.align="center";
           
           //row.innerHTML +='< onMouseOver = "test(this);" >';           
      } 



------解决方案--------------------
function tbAdd(data_scroll, data_name, data_kind, data_qualit, data_dest, data_total, data_price, data_least, data_time, data_urlID) {
var tb = document.getElementById("dest_tb");
rowIndex = tb.rows.length;
var row = tb.insertRow(rowIndex);
/////////////////////////////////////////////////////
row.onmouseover = row.onmouseout = function (e) {
e = e || window.event;
this.style.background = e.type == 'mouseover' ? '#00cc00' : '#339900'
}
/////////////////////////////////////////////////////

if (data_scroll % 2 == 0)
row.bgColor = "#cccccc"

var scroll = row.insertCell(0);
scroll.width = "50px";
scroll.height = "40px";
if (data_urlID.length != 0)
scroll.innerHTML = data_scroll;
else
scroll.innerHTML = "";
scroll.style.fontSize = "14px";
scroll.align = "center";
var name = row.insertCell(1);
name.width = "150px";
name.innerHTML = data_name;
name.style.fontSize = "14px";
name.align = "center";
var kind = row.insertCell(2);
kind.width = "80px";
kind.innerHTML = data_kind;
kind.style.fontSize = "14px";
kind.align = "center";
var qualit = row.insertCell(3);
qualit.width = "110px";
qualit.innerHTML = data_qualit;
qualit.style.fontSize = "14px";
qualit.align = "center";
  相关解决方案