刚才的提问得到结果了,但是发现一旦嵌套了表格就出错,应该是没有加上id属性吧。
怎样在嵌套表格里实现这样的点击效果(我很菜,请帮我在必要的地方加上ID):
以下是百度网页搜索代码:<table>
  <tr>
    <td><table>
      <tr align="center">
        <td style="background-color:#0FF"><a href="javascript:">网页</a></td>
        <td><a href="javascript:">音乐</a></td>
      </tr>
      <tr>
        <td colspan="2"><form action="http://www.baidu.com/s" target="_blank">
          <input name="word" type="text" value="" />
          <input name="submit" type="submit" value="百度一下" />
        </form></td>
      </tr>
    </table></td>
    <td><table>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>怎样实现点击“音乐”链接后,单元格改变颜色,搜索代码改为音乐搜索?效果:<table>
  <tr>
    <td><table>
  <tr align="center">
    <td><a href="javascript:">网页</a></td>
    <td bgcolor="#00FFFF"><a href="javascript:">音乐</a></td>
  </tr>
  <tr>
    <td colspan="2">
<form action="http://mp3.baidu.com/m" target="_blank">
    <input name="word" type="text" value="">
    <input type="submit" value="百度一下">
</form></td>
  </tr>
</table></td>
    <td><table>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>

解决方案 »

  1.   

    结贴真是速度啊,刚在原帖中回了。。
    <!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=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    window.onload = function() {
    var c = document.getElementById('controller').getElementsByTagName('td');
    var ar = ['http://www.baidu.com/s', 'http:m.baidu.com/m'];
    for(var i = 0; i < c.length; i ++) {
    c[i].onclick = function() {
    c[0].style.backgroundColor = '#FFF';
    c[1].style.backgroundColor = '#FFF';
    c[this.cellIndex].style.backgroundColor = '#0FF';
    document.getElementById('searcher').action = ar[this.cellIndex];
    }
    }
    }
    </script>
    </head><body>
    <table>
      <tr align="center" id="controller">
        <td style="background-color:#0FF"><a href="javascript:">网页</a></td>
        <td><a href="javascript:">音乐</a></td>
      </tr>
      <tr>
        <td colspan="2">
        <form action="http://www.baidu.com/s" target="_blank" id="searcher">
          <input name="word" type="text" value="" />
          <input type="submit" value="百度一下" />
        </form></td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    复制到Dreamweaver里面就清楚了,刚才提问的简单,但是一嵌套就出错
      

  3.   

    var ar = ['http://www.baidu.com/s', 'http://mp3.baidu.com/m'];
      

  4.   

    好了,谢谢!先加到50分再结贴:)
    刚才接了的那个贴子里看你提到DOM这个词,第一次听说呢,搜索查了一下才明白一点——高人啊!
    你script标签里的程序使用什么工具写的?我只会模仿别人的代码,在Dreamweaver里手工输入,很菜。
      

  5.   

    还有,方便的话告诉我该学学哪方面的知识,你script标签里的程序使用什么工具写的?
      

  6.   

    什么工具不重要,我也是在Dreamweaver中写的,任何一个最基本的文本编辑器都可以,记事本里也一样。
    学习JS可以先看看网上的基础教程,比如http://www.w3school.com.cn/js/index.asp
      

  7.   

    document.getElementById('controller').getElementsByTagName('td')——这样的代码都是一个字母一个字母打出来的啊?我以为是什么工具生成的呢!
    把你的网址收藏起来了,有时间学学~~