<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>选项卡</title>
<style>
*{
margin:0;
padding: 0;
}
div{
width: 300px;
height: 300px;
border: 1px solid red;
text-align: center;
line-height: 200px;
display: none;
}
#div1{
display: block;
}
button{
display: inline;
width: 100px;
height: 20px;
margin-right: -4px;/*去掉多个按钮之间默认的间距*/
}
</style>
<script>
window.onload=function(){
var aInput=document.getElementsByTagName('button');
var oDiv=document.getElementsByTagName('div');
var n=0;
for(var i = 0;i < aInput.length;i++){
aInput[i].index=i;
aInput[i].onclick=function(){
aInput[n].style.background="";//先把下标为0的按钮背景颜色清空
oDiv[n].style.display="none";
this.style.background="red";//点击当前的按钮,给当前按钮一个红色背景
oDiv[this.index].style.display="block";
n=this.index;
}
}
}
</script>
</head>
<body>
<button style="background: red;"/>tab1</button>
<button>tab2</button>
<button>tab3</button>
<div id="div1">
我是tab1里的内容
</div>
<div>
我是tab2里的内容
</div>
<div>
我是tab3里的内容
</div>
</body>
</html>

最新文章

  1. 如何利用ETW(Event Tracing for Windows)记录日志
  2. 后台PageVo中字段赋值与前台datagrid字段获取
  3. Linux UserSpace Back-Door、Rootkit SSH/PAM Backdoor Attack And Defensive Tchnology
  4. 新浪微博授权失败:applications over the unaudited use restrictions
  5. android 不一样的学习记录
  6. c#线程创建
  7. Ubuntu14.04 如何修改/etc/sudoers 和错误修改权限的解决办法
  8. hdu4497 正整数唯一分解定理应用
  9. Go代理,修改标题
  10. VS2010新建Web网站与新建Web应用程序的区别
  11. 备忘录模式(Memento)
  12. rpm安装查看卸载软件
  13. 【NLP】依存句法关系符号解释
  14. 2018年10月OKR初步规划
  15. jquery on()方法重复绑定解决方法
  16. ios开发:一个音乐播放器的设计与实现
  17. Maven内存修改
  18. [日常] Go语言圣经--并发的web爬虫
  19. 解决 Ubuntu 14.04 图形界面无法正常显示 问题
  20. 『PyTorch』第十一弹_torch.optim优化器

热门文章

  1. 简单分析android textview xml 的属性设置
  2. 【转】android webview设置内容的字体大小
  3. Android中常用的颜色
  4. Xamarin Mono 环境搭建
  5. 动手Jquery插件
  6. 用Python复习离散数学(一)
  7. 上传组件uploadify的使用
  8. FAQ:仓储实现为什么在基础设施层?
  9. 网络负载均衡环境下wsHttpBinding+Message Security+Windows Authentication的常见异常
  10. web前端安全---读书笔记