javascript简单选项卡,一个页面可多次引用

本文介绍了一种使用HTML和JavaScript实现的选项卡效果,通过简单的鼠标悬停事件切换不同的内容区块,展示了基本的网页交互设计。
<!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>
<script language="javascript" type="text/javascript">
<!--
function setTab(name,cursel,n){
 for(i=1;i<=n;i++){
  var menu=document.getElementById(name+i);
  var con=document.getElementById("con_"+name+"_"+i);
  menu.className=i==cursel?"hover":"";
  con.style.display=i==cursel?"block":"none";
 }
}
//-->
</script>
<style type="text/css">
*{ margin:0; padding:0;}
li{ list-style:none;}
.main{ width:230px; border:solid 1px #e0e0e0; border-width:1px 1px 1px 0; margin:20px;}
.Menubox{
	width:100%;
	height:32px;
	line-height:32px;
}
.Menubox li{
	float:left;
	display:block;
	cursor:pointer;
	width:115px; height:32px;
	text-align:center;
	border:solid 1px #e0e0e0;
	border-width:0 0 1px 0;
	background:url(bg_li.gif) no-repeat left #f9f9f9;
}
.Menubox li.hover{
	width:115px;
	height:33px;
	border-bottom:none;
	color:#ec1c5f;
	font-weight:bold;
	background:url(bg_li.gif) no-repeat left #fff;
}
.Contentbox,.Contentbox1{
	border-left:solid 1px #e0e0e0;
	padding:10px;
	clear:both;
}
</style>
</head>

<body>
<div class="main">

<div class="Menubox">
    <ul>
       <li id="one1" onMouseOver="setTab('one',1,2)"  class="hover">新闻资讯</li>
       <li id="one2" onMouseOver="setTab('one',2,2)">最新动态</li>
    </ul>
</div>
<div class="Contentbox">
     <div class="free_mer1" id="con_one_1" style="display:;">新闻资讯</div>
     <div class="free_mer1" id="con_one_2" style="display:none;">最新动态</div>
</div>

</div>
</body>
</html>

用到的图片:bg_li.gif

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值