切换
2016-07-12 08:26
302 查看
<!DOCTYPE html>
<html>
<head>
<meta
charset="UTF-8">
<title></title>
<style
type="text/css">
.show{
width:
100px;
height:
100px;
background-color: red;
font-size:
50px;
color: white;
display:
block;
}
div{
display:
none;
}
.active{
width:
50;
height:
20px;
background-color: yellow;
}
</style>
</head>
<body>
<input
type="button"
name="" id=""
value="按钮1" />
<input
type="button"
name="" id=""
value="按钮2" />
<input
type="button"
name="" id=""
value="按钮3" />
<div class="show">A</div>
<div>B</div>
<div>C</div>
<script
type="text/javascript">
var
aDiv = document.getElementsByTagName("div");
var
aInput = document.getElementsByTagName("input");
// // 按钮1
// aInput[0].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[0].className = "show";
// aInput[0].className = "active";
// }
//
// aInput[1].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[1].className = "show";
// aInput[1].className = "active"; nn
// }
// aInput[2].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[2].className = "show";
// aInput[2].className = "active";
// }
// 为了绑定事件循环三次
for
(var i = 0; i
< aInput.length; i++) {
// 给input标签添加一个属性index 用于保存他的下标
aInput[i].index
= i;
aInput[i].onclick
= function (){
for
(var j = 0; j
< aInput.length; j++) {
// 先清除样式,再加样式
aInput[j].className
= "";
aDiv[j].className
= "";
}
this.className
= "active";
aDiv[this.index].className
= "show";
}
}
</script>
</body>
</html>
<html>
<head>
<meta
charset="UTF-8">
<title></title>
<style
type="text/css">
.show{
width:
100px;
height:
100px;
background-color: red;
font-size:
50px;
color: white;
display:
block;
}
div{
display:
none;
}
.active{
width:
50;
height:
20px;
background-color: yellow;
}
</style>
</head>
<body>
<input
type="button"
name="" id=""
value="按钮1" />
<input
type="button"
name="" id=""
value="按钮2" />
<input
type="button"
name="" id=""
value="按钮3" />
<div class="show">A</div>
<div>B</div>
<div>C</div>
<script
type="text/javascript">
var
aDiv = document.getElementsByTagName("div");
var
aInput = document.getElementsByTagName("input");
// // 按钮1
// aInput[0].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[0].className = "show";
// aInput[0].className = "active";
// }
//
// aInput[1].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[1].className = "show";
// aInput[1].className = "active"; nn
// }
// aInput[2].onclick = function (){
// for (var i = 0; i < aInput.length; i++) {
// aInput[i].className = "";
// aDiv[i].className = "";
// }
// aDiv[2].className = "show";
// aInput[2].className = "active";
// }
// 为了绑定事件循环三次
for
(var i = 0; i
< aInput.length; i++) {
// 给input标签添加一个属性index 用于保存他的下标
aInput[i].index
= i;
aInput[i].onclick
= function (){
for
(var j = 0; j
< aInput.length; j++) {
// 先清除样式,再加样式
aInput[j].className
= "";
aDiv[j].className
= "";
}
this.className
= "active";
aDiv[this.index].className
= "show";
}
}
</script>
</body>
</html>
相关文章推荐
- Extjs4.0 最新最全视频教程
- Javascript中toFixed方法的改进
- 5个常见可用性错误和解决方案
- js数组实现图片轮播
- js可突破windows弹退效果代码
- JSP脚本漏洞面面观
- 使用BAT一句话命令实现快速合并JS、CSS
- js显示当前星期的起止日期的脚本
- 爆炸式的JS圆形浮动菜单特效代码
- jquery马赛克拼接翻转效果代码分享
- Oracle数据库 DGbroker三种保护模式的切换
- js select常用操作控制代码
- JS实现不使用图片仿Windows右键菜单效果代码
- 从jsp发送动态图像
- 原生js结合html5制作小飞龙的简易跳球
- js 页面模块自由拖动实例
- js实现小鱼吐泡泡在页面游动特效
- js 提交和设置表单的值
- PHP VBS JS 函数 对照表
- node.js抓取并分析网页内容有无特殊内容的js文件