首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

这段脚本不知如何写,大家帮帮忙

2012-02-04 
这段脚本不知怎么写,大家帮帮忙scriptfunctionshow(cue){document.getElementById(cue).style.display

这段脚本不知怎么写,大家帮帮忙
<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>

热点排行