jQuery slideToggle() 方法 多个div怎么写

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideToggle("slow");
});
});
</script>

<style type="text/css">
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
div.panel
{
height:120px;
display:none;
}
</style>
</head>

<body>

<div class="panel">
<p>W3School - 领先的 Web 技术教程站点</p>
<p>在 W3School,你可以找到你所需要的所有网站建设教程。</p>
</div>

<p class="flip">请点击这里</p>

</body>
</html>

<!DOCTYPE html>
<html>

<head>
    <script src="/jquery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $(".flip").click(function() {
                $(".panel:eq(" + $(this).index(".flip") + ")").slideToggle("slow");
            });
        });
    </script>
    <style type="text/css">
        div.panel,p.flip {
    margin: 0px;
    padding: 5px;
    text-align: center;
    background: #e5eecc;
    border: solid 1px #c3c3c3;
}

div.panel {
    height: 120px;
    display: none;
}
    </style>
</head>

<body>
    <div class="panel">
        <p>W3School - 领先的 Web 技术教程站点</p>
        <p>在 W3School,你可以找到你所需要的所有网站建设教程。</p>
    </div>
    <p class="flip">请点击这里</p>
    <div class="panel">
        <p>W3School - 领先的 Web 技术教程站点</p>
        <p>在 W3School,你可以找到你所需要的所有网站建设教程。</p>
    </div>
    <p class="flip">请点击这里</p>
</body>

</html>

温馨提示:答案为网友推荐,仅供参考