日期:2014-05-16 浏览次数:20539 次
<table>
<tr align="center">
<td bgcolor="#00FFFF"><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 type="submit" value="百度一下" />
</form></td>
</tr>
</table>
<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>
<!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 tr1 = document.getElementsByTagName('table')[0].getElementsByTagName('tr')[0];
var f = document.getElementsByTagName('table')[0].getElementsByTagName('form')[0];
tr1.getElementsByTagName('td')[0].onclick = function() {
this.style.backgroundColor = '#0FF';
tr1.getElementsByTagName('td')[1].style.backgroundColor = '#FFF';
f.action = 'http://www.baidu.com/s';
}
tr1.getElementsByTagName('td')[1].onclick = function() {
this.style.backgroundColor = '#0FF';
tr1.getElementsByTagName('td')[0].style.backgroundColor = '#FFF';
f.action = 'http://mp3.baidu.com/m';
}
}
</script>
</head>
<body>
<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 type="submit" value="百度一下" />
</form></td>
</tr>
</table>
</body>
</html>
------解决方案--------------------
<script>
function doit(n){
var tbl = document.body.getElementsByTagName("table")[0];
for(var i=0;i<tbl.rows[0].cells.length;i++) tbl.rows[0].cells[i].style.background = "#FFF";
switch(n){
case 0:
tbl.rows[0].cells[0].style.background = "#0FF";
document.forms[0].action = "http://www.baidu.com/s";
break;
case 1:
tbl.rows[0].cells[1].style.