用dom实现像优快云论坛的显示的功能

本文介绍了一个使用HTML和JavaScript实现的下拉菜单示例。当鼠标悬停在顶部导航栏的不同选项上时,相应的子菜单会显示出来,同时改变背景颜色。此示例展示了如何通过简单的JavaScript函数控制元素的显示与隐藏,并更改其样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如图所示

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
 
function show_onOver(a)
 
{
  
var theTrId;
  
for(var i=1; i<=6; i++)
  
{
   theTrId 
= "trShow" + i;
   
if(i==a)
    document.getElementById(theTrId).style.display 
= "block";
   
else
    document.getElementById(theTrId).style.display 
= "none";
  }

 }


 
function onloadFun()
 
{
  
var theTrId;
  
for(var i=1; i<=6 ; i++)
  
{
   theTrId 
= "trShow" + i;
   document.getElementById(theTrId).style.display 
= "none";
  }

 }

</script>

</head>
<body onLoad="onloadFun()"> 
<table width="100%%"  border="0" cellspacing="0" cellpadding="0" id="theTableId"> 
  
<tr> 
    
<td id="1"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">新闻   </td> 
    
<td id="2"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">博客</td> 
    
<td id="3"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">论坛</td> 
    
<td id="4"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">图书</td> 
    
<td id="5"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">介绍</td> 
    
<td id="6"  onmouseover="this.bgColor='#C4DFF7';show_onOver(this.id)" onmouseout="this.bgColor='#ffffff';show_onOut(this.id)">其他</td> 
  
</tr> 
  
<tr> 
 
<td id="trShow1" colspan="6"> 
  
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#CC6699"> 
   
<tr> 
    
<td>新闻 - Hello World! </td> 
   
</tr> 
   
</table>
 
</td> 
  
</tr> 
 
<tr id="trShow2"> 
  
<td colspan="6"> 
   
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#9999ff"> 
    
<tr> 
     
<td>博客 - Hello World! </td> 
    
</tr> 
   
</table>
  
</td> 
   
</tr> 
 
 
<tr id="trShow3"> 
  
<td colspan="6"> 
   
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#ff9933"> 
    
<tr> 
     
<td>论坛 - Hello World! </td> 
    
</tr> 
   
</table>
  
</td> 
   
</tr> 
 
 
<tr id="trShow4"> 
  
<td colspan="6"> 
   
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#99ee44"> 
    
<tr> 
     
<td> 图书 - Hello World! </td> 
    
</tr> 
   
</table>
  
</td> 
   
</tr> 
 
 
<tr id="trShow5"> 
  
<td colspan="6"> 
   
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#00CCFF"> 
    
<tr> 
     
<td> 介绍 - Hello World! </td> 
    
</tr> 
    
</table>
  
</td> 
   
</tr> 
 
 
<tr id="trShow6"> 
  
<td colspan="6"> 
   
<table width="100%%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#006600"> 
    
<tr> 
     
<td>其他 - Hello World! </td> 
    
</tr> 
    
</table>
  
</td> 
   
</tr> 
</table> 
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值