日期:2014-05-16  浏览次数:20329 次

这段脚本不知怎么写,大家帮帮忙
<script>
function   show(cue)
{  
      document.getElementById(cue).style.display= ' ';  
}
</script>

<a   href= '# '   name=href1     onclick= 'show(0) '> 北京 </a>
<a   href= '# '   name=href1     onclick= 'show(1) '> 广州 </a>
<a   href= '# '   name=href1     onclick= 'show(2) '> 杭州 </a>

<table   bgcolor=green   style= 'display:none; '   width=100%   runat=server     id=0> <tr> <td> 北京 </td> </tr> </table>
<table   bgcolor=green   style= 'display:none; '   width=100%   runat=server     id=1> <tr> <td> 广州 </td> </tr> </table>
<table   bgcolor=green   style= 'display:none; '   width=100%   runat=server     id=2> <tr> <td> 杭州 </td> </tr> </table>
点击 "北京 ",对应的table就显示出来,我写的那句脚本不对,当我点击广州的时候
,上一次的应该隐藏掉,请问如何控制?谢谢

------解决方案--------------------
//稍做修改,这样应该可以吧~

<script>
//全局变量,用来保存当前显显示的对象的ID
var showId= '0 ';
function show(cue)
{
var showObj=document.getElementById(showId);
if(showObj)
showObj.style.display= 'none ';
document.getElementById(cue).style.display= ' ';
showId=cue;
}
</script>

<a href= '# ' name=href1 onclick= 'show(0) '> 北京 </a>
<a href= '# ' name=href1 onclick= 'show(1) '> 广州 </a>
<a href= '# ' name=href1 onclick= 'show(2) '> 杭州 </a>

<table bgcolor=green style= 'display:none; ' width=100% runat=server id=0> <tr> <td> 北京 </td> </tr> </table>
<table bgcolor=green style= 'display:none; ' width=100% runat=server id=1> <tr> <td> 广州 </td> </tr> </table>
<table bgcolor=green style= 'display:none; ' width=100% runat=server id=2> <tr> <td> 杭州 </td> </tr> </table>