0
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"><script>

<script>
$(document).ready(function() 
{
    $('.sss').filter(':nth-child(n+2)').hide();
    $('.sss').on('mouseenter', '.question', function() 
    {   
        $(this).next().slideDown(200).siblings('.answer').slideUp(200);
    });
});
</script>
</head>
<div class="sss">
    <div class="question">Question</div>
    <div class="answer">Answer</div>

    <div class="question">Question</div>
    <div class="answer">Answer</div>

    <div class="question">Question</div>
    <div class="answer">Answer</div>

    <div class="question">Question</div>
    <div class="answer">Answer</div>
</div>

Divs 没有父子关系还是我在这里做错了?

4

2 回答 2

2

试试这个:

$('.sss').children().filter(':nth-child(n+2)').hide();

如果您需要所有questiondiv,请尝试:

$('.sss').children(':nth-child(2n)').hide();

或者

$('.sss .question').hide();

对于所有人answer

$('.sss').children(':nth-child(2n+1)').hide();

或者

$('.sss .answer').hide();
于 2012-09-11T09:32:59.110 回答
0

这是不使用过滤器的替代方法:

$('.sss').children(':nth-child(n+2)').hide();
于 2012-09-11T09:41:10.610 回答