JS显示隐藏层类

 

<!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>JS显示隐藏层类</title>

</head>

 

<body>

<div id="box">

<a href="#" id="a0">wewegwg</a> <a href="#" id="a1">weg</a> <a href="#" id="a2">wrgwe</a> <a href="#" id="a3">wegt</a> <a href="#">weg</a> <a href="#">we</a></div>

<div id="box2">

<div id="e0">

wgwegwegweg

rwegvwvwgv

</div>

 

<div id="e1">

ergwergergewrgerg

</div>

 

<div id="e2">

egergerwg

</div>

 

<div id="e3">

regrewgererherhe

</div>

</div>

<script language="javascript">

function $(id){return document.getElementById(id);}

function chlayer_display(layers){

 this.ch = function(index){

for(var i=0;i<this.contents.length;i++){

this.contents[i].style.display = 'none';

}

this.contents[index].style.display = 'block';

 }

 this.init = function(){

for(var i=0;i<this.controls.length;i++){

 this.controls[i].value = i;

 var _this = this;

 this.controls[i].onmousemove = function(){

 _this.ch(this.value);

 };

}

if(typeof this.checked != 'undefined'){

this.ch(this.checked);

} else {

this.ch(0);

}

 }

 if(typeof layers == 'object'){

 this.controls = [];

 this.contents = [];

for(var i=j=0;i<layers.length;i++){

 if(typeof layers[i].control=='object'&&typeof layers[i].content=='object'){

this.controls[j] = layers[i].control;

this.contents[j] = layers[i].content;

if(layers[j].checked){this.checked = j};

j++;

 } else {

continue;

 }

}

if(this.controls.length > 0 && this.contents.length > 0){this.init()};

 }

 

}

/*var aaa = new chlayer_display([

{

'control':$('a0'),

'content':$('e0'),

'checked':true

},

{

'control':$('a1'),

'content':$('e1')

},

{

'control':$('a2'),

'content':$('e2')

},

{

'control':$('a3'),

'content':$('e3')

}

]);*/

 

var aaa = new chlayer_display();

aaa.controls = $('box').getElementsByTagName('a');

aaa.contents = $('box2').getElementsByTagName('div');

aaa.init();

 

 

 

</script>

</body>

</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值