对与高手很简单的问题,菜鸟求教.

song1pan 2009-06-04 09:33:29
我是新手,能帮我看看下面代码能不能优化,哪里不要改的.
随便说两句也成.

<!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>导航</title>

<style>
<!--
.start {
background-color:gray;
color:#CC0000;
font-family:"宋体";
over:expression(onmouseover=function(){if(this.className!='click')this.className='over'});
out:expression(onmouseout=function(){if(this.className=='over')this.className='out'});
}
.click {
background-color:#0FF;
color:#CC0000;
}
.over{
background-color:#3CF;
color:#CC0000;
}
.out{
background-color:gray;
color:#CC0000;
font-family:"宋体";
}
-->
</style>
</head>
<script language="javascript">
function tag(obj) {
var o = document.getElementById(obj.id);
o.className=(o.className=="click"?"over":"click");
//alert("请帮忙实现功能,记录当前的表格改变成click样式,还原其他的表格为start样式.");
for( var i=1; i<=5; i++) {
var tag = "td"+i;
if( obj.id != tag) {
document.getElementById(tag).className="start";
}
}

}
</script>
<body>
<table id="table" class="table" width="300" border="1" align="center">
<tr id="tr">
<td width="20%" id="td1" class="start" onclick="javascript:tag(this)">菜单1</td>
<td width="20%" id="td2" class="start" onclick="javascript:tag(this)">菜单2</td>
<td width="20%" id="td3" class="start" onclick="javascript:tag(this)">菜单3</td>
<td width="20%" id="td4" class="start" onclick="javascript:tag(this)">菜单4</td>
<td width="20%" id="td5" class="start" onclick="javascript:tag(this)">菜单5</td>
</tr>
</table>
</body>
</html>
...全文
19 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rexuenaner929 2009-06-04
  • 打赏
  • 举报
回复
var o = document.getElementById(obj.id);
这句用来做什么啊,把对象赋值给o吗,这样一来,o和obj代表的对象不就是一模一样的吗,所以感觉没有必要要这句吧,obj已经是你要的对象了
song1pan 2009-06-04
  • 打赏
  • 举报
回复
随便提点意见.

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧