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