<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>

解决方案 »

  1.   

    ??楼上的代码看着眼熟,好像是改我的:)
    <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>
      

  2.   

    NO,NO,NO,NO,不是要点层的!!而是通过 show 将最后打开的层!!显示在最上面!!
      

  3.   

    都争啥?以为我不在就可以随便copy我的代码  :P
      

  4.   

    多加两个变量即可
    c = a;
    a = b;
    b = c;
      

  5.   

    show 出来的层,首先是给他的固定位置不是吗?  比如 z-index:5但是,如果实现 动作 show 的时候 z-index=max 呢?
      

  6.   

    呵呵~~
    楼主运行一下我的代码看看再说啊~
    为了让你看效果,我专门让z-index搞的层先现实哦:)
      

  7.   

    楼主要的是否是这种效果,不管点哪个层,该层和最上面那层的位置互换?<body>
    <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>
      

  8.   

    不是这样的效果!!首先,所有的层是隐藏的!!通过show  将层显示出来!!比如,现在show出了第5层,如果在这个层上点击3次的话,这个层的层次为8当我在 show 出第4层的时候,层次为4,当然显示在5 层的后面!必修要点击依次,才可以将他显示在前面!我想要的效果是!show 出第4层,就显示在最前面!
      

  9.   

    晕!你有没有运行我的代码看看???????
    难道不是一个一个show出来的?难道最后出来的不在最上边?
    faint!
      

  10.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <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>
      

  11.   

    给你改了!希望以后不要总想着要现成的代码,否则永远学不会。
    <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>
      

  12.   

    thank you ! xinyunyishui(心云意水) 俺会记住您的啦!!