1 现在有个列表table, 格式如下
list_a
list_b
list_c
...
list_n
我希望, 当我click其它的item时, 之前click的恢复到以前的颜色, 而click的改变颜色.
2 我现在有一些img类型的图片按扭, 我希望当我的鼠标mouseover时, 改变<td>的背景颜色, 而当我onmouseout时, 恢复以前颜色(注意:我用的背景图片), html代码如下:
<table cellSpacing=0 cellPadding=3 width="100%" border=0 class=form-noindent background="image/tool-bkgd.gif">
  <tbody>
    <tr>
  <td width="1%" height="15" onmouseover="this.bgColor='#C3D5ED'"; onmouseout="this.background=image/delete.gif";><img style="cursor:hand" src="image/addtd.gif" onClick="addteam();"></td>
</tr>
</tbody>
</table>
谢谢

解决方案 »

  1.   

    1,用一变量保存当前item,点击其它时,变量指向item复原,变量指向点击的item
    2,var arTd=oTable.getElementsByTagName("td")
    for(var i=0;i<arTd.length;i++){
      arTd[i].onmouseover=function(){
        this.style.background="url(...)"
      }
      arTd[i].onmouseout=function(){
        this.style.background="url(...)"
      }
    }
      

  2.   

    不要去循環行處理,直接在TABLE上監聽事件,透過event.srcElement來做處理!設置一個nowRow來記錄當前選中的行。
      

  3.   

    如果用nowrow具体如何去做, 我对js很不熟悉
      

  4.   

    第一个问题<!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>
    </head>
    <body>
    <table width="200" border="1" id="tab">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table><script type="text/javascript">
    window.onload=function(){
    var tab = document.getElementById("tab");
    for(var i=0;i<tab.rows.length;i++)
    {
    tab.rows[i].onclick = function(){
    if(tab.temp)
    tab.temp.style.backgroundColor = "";

    this.style.backgroundColor = "#cccccc";
    tab.temp = this;
    }
    }
    }
    </script>
    </body>
    </html>
      

  5.   

    第二个,应该是这样吧,不知道我有没理解错……
    <!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>
    </head>
    <style type="text/css">
    .default{background-image:url("http://www.google.cn/options/icons/picasa.gif")}/*默认图片*/
    .over{background-image:url("http://www.google.cn/options/icons/patent.gif")}
    </style>
    <body>
    <table width="200" border="1" id="tab">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="http://www.google.cn/options/icons/chrome.gif" name="test" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="http://www.google.cn/options/icons/chrome.gif" name="test" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="http://www.google.cn/options/icons/chrome.gif" name="test" /></td>
      </tr>
    </table><script type="text/javascript">
    window.onload=function(){
    var imgs = document.getElementsByName("test");
    for(var i=0;i<imgs.length;i++)
    {
    imgs[i].parentNode.className = "default";
    imgs[i].onmouseover = function(){
    this.parentNode.className = "over";
    }
    imgs[i].onmouseout = function(){
    this.parentNode.className = "default";
    }
    }
    }
    </script>
    </body>
    </html>