使用jQuery更改重叠图像z-index

Dav*_*ldo 6 html css jquery z-index

我有三个矩形图像重叠在一条对角线内,第一个在左上角完全可见,第二个在中央部分隐藏在第一个,最后一个在右下角部分隐藏在第二个.我想要点击的图像在其他图像之上.我试图通过使用jQuery操纵z-index来实现这一点,但它似乎不起作用.实际上看起来jQuery甚至都没有得到认可.

这是我的测试代码:

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js">
    $(document).ready(function () {
        $('#launch').click(function () {
            alert('Ok');
        });

        $('.bottom-pic').click(function () {
            $(this).css('z-index' : '1');
            $('.bottom-pic').not(this).css('z-index' : '0');
        });
    });
    </script>
    <style type="text/css">
    #pictures {
        width: 650px;
        height: 300px;

        margin-left: auto;
        margin-right: auto;
        margin-top: 20px;
        margin-bottom: 50px;

        position: relative;
    }

    #top {
        top: 0;
        left: 0;

        position: absolute; 
        z-index: 1;
    }

    #center {
        top: 60px; 
        left: 200px;

        position: absolute; 
        z-index: 1;
    }

    #bottom {
        top: 150px; 
        left: 400px; 

        position: absolute; 
        z-index: 0;
    }
    </style>
    </head>
    <body>
    <div id="pictures">
         <img src="bottom-pic.jpg" id="top" class="bottom-pic">
         <img src="bottom-pic.jpg" id="center" class="bottom-pic">
         <img src="bottom-pic.jpg" id="bottom" class="bottom-pic">
    </div>
    <input type="button" value="Try" id="launch">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我点击"启动"按钮时,甚至都没有发生.

Ahm*_*sud 1

好吧,我刚刚意识到你犯了一个小错误,你使用相同的标签来加载查询和声明你的内联 JavaScript...你不能这样做。您必须使用两个单独的脚本标签。

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js">
    </script> 
Run Code Online (Sandbox Code Playgroud)

注意新的脚本标签:

  <script type="text/javascript">
    $(document).ready(function () {
        $('#launch').click(function () {
            alert('Ok');
        });

        $('.bottom-pic').click(function () {
            $(this).css('z-index', '1');
            $('.bottom-pic').not(this).css('z-index', '0');
        });
    });
   </script>
Run Code Online (Sandbox Code Playgroud)

...

答案的其余部分仍然适用..也就是说,你必须摆脱 #top、#middle 和 #bottom 中的 z-index....