<div style="position:absolute;background-color:red;top:100;left:100;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div style="position:absolute;background-color:green;top:120;left:120;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div style="position:absolute;background-color:yellow;top:140;left:140;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div style="position:absolute;background-color:blue;top:160;left:160;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="a" style="position:absolute;background-color:black;top:180;left:180;width:100;height:100;z-index:1" onclick="set(this)"></div>
<script language="javascript">
var i = 2;
<!--
function set(o)
{
o.style.zIndex = i;
i++;
}
//-->
</script>
<div style="position:absolute;background-color:green;top:120;left:120;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div style="position:absolute;background-color:yellow;top:140;left:140;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div style="position:absolute;background-color:blue;top:160;left:160;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="a" style="position:absolute;background-color:black;top:180;left:180;width:100;height:100;z-index:1" onclick="set(this)"></div>
<script language="javascript">
var i = 2;
<!--
function set(o)
{
o.style.zIndex = i;
i++;
}
//-->
</script>
<body onload="show()">
<div id="ys1" style="position:absolute;background-color:red;top:100;left:100;width:100;height:100;z-index:1;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys2" style="position:absolute;background-color:green;top:120;left:120;width:100;height:100;z-index:2;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys3" style="position:absolute;background-color:yellow;top:140;left:140;width:100;height:100;z-index:3;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys4" style="position:absolute;background-color:blue;top:160;left:160;width:100;height:100;z-index:4;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys5" style="position:absolute;background-color:black;top:180;left:180;width:100;height:100;z-index:5;display:none" onclick="this.style.zIndex=max++;"></div>
<script language=JavaScript>
var max=6;
var i=5;
function show()
{eval("ys"+i).style.display="";
eval("ys"+i--).style.zIndex=max++;
if(i>0)
setTimeout("show()",500);
}
</script>
c = a;
a = b;
b = c;
楼主运行一下我的代码看看再说啊~
为了让你看效果,我专门让z-index搞的层先现实哦:)
<div id="d" style="position:absolute;background-color:red;top:100;left:100;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="d" style="position:absolute;background-color:green;top:120;left:120;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="d" style="position:absolute;background-color:yellow;top:140;left:140;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="d" style="position:absolute;background-color:blue;top:160;left:160;width:100;height:100;z-index:1" onclick="set(this)"></div>
<div id="d" style="position:absolute;background-color:black;top:180;left:180;width:100;height:100;z-index:1" onclick="set(this)"></div><script language="javascript">
var i = 2;
var obj = document.all.d[0];function set(o)
{
var x,y;
x = o.style.left;
y = o.style.top;
o.style.left = obj.style.left;
o.style.top = obj.style.top;
obj.style.left = x;
obj.style.top = y;
o.style.zIndex = i;
i++;
obj = o;
}
</script>
</body>
难道不是一个一个show出来的?难道最后出来的不在最上边?
faint!
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
</script>
<BODY>
<script>var max=5;</script>
<div style="position:absolute; background-color:red; top:100; left:100; width:100; height:100; z-index:1; visibility: hidden;" onclick="max++;this.style.zIndex=max;" id="l1"></div>
<div style="position:absolute; background-color:green; top:120; left:120; width:100; height:100; z-index:2; visibility: hidden;" onclick="max++;this.style.zIndex=max;" id="l2"></div>
<div style="position:absolute; background-color:yellow; top:140; left:140; width:100; height:100; z-index:3; visibility: hidden;" onclick="max++;this.style.zIndex=max;" id="l3"></div>
<div style="position:absolute; background-color:blue; top:160; left:160; width:100; height:100; z-index:4; visibility: hidden;" onclick="max++;this.style.zIndex=max;" id="l4"></div>
<div style="position:absolute; background-color:black; top:180; left:180; width:100; height:100; z-index:5; visibility: hidden;" onclick="max++;this.style.zIndex=max;" id="l5"></div><p><a href="#" onClick="MM_showHideLayers('l1','','show')">1层</a> <a href="#" onClick="MM_showHideLayers('l2','','show')">2层</a>
<a href="#" onClick="MM_showHideLayers('l3','','show')">3层</a> <a href="#" onClick="MM_showHideLayers('l4','','show')">4层</a>
<a href="#" onClick="MM_showHideLayers('l5','','show')">5层</a></p>
</BODY>
</HTML>
<div id="ys1" style="position:absolute;background-color:red;top:100;left:100;width:100;height:100;z-index:1;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys2" style="position:absolute;background-color:green;top:120;left:120;width:100;height:100;z-index:2;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys3" style="position:absolute;background-color:yellow;top:140;left:140;width:100;height:100;z-index:3;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys4" style="position:absolute;background-color:blue;top:160;left:160;width:100;height:100;z-index:4;display:none" onclick="this.style.zIndex=max++;"></div>
<div id="ys5" style="position:absolute;background-color:black;top:180;left:180;width:100;height:100;z-index:5;display:none" onclick="this.style.zIndex=max++;"></div>
<script language=JavaScript>
var max=6;
var i=5;
function show(o)
{eval(o).style.display="";
eval(o).style.zIndex=max++;
}
</script>
<a href="#" onClick="show('ys1')">1层</a>
<a href="#" onClick="show('ys2')">2层</a>
<a href="#" onClick="show('ys3')">3层</a>
<a href="#" onClick="show('ys4')">4层</a>
<a href="#" onClick="show('ys5')">5层</a>