0

假设我有一个这样的列表:

<ul class="list">
<li><span class="pos"><div class="txt_pos">1</div></li>
<li><span class="pos"><div class="txt_pos">2</div></li>
<li><span class="pos"><div class="txt_pos">3</div></li>
<li><span class="pos"><div class="txt_pos">4</div></li>
<li><span class="pos"><div class="txt_pos">5</div></li>
</ul>

和我的 JS:

$(".list span.pos").each(function(i) {
    var newOne = i;
    newRank = getNth(newOne);

    $("> .txt_pos").slideToggle('slow');
    $(this).text(newRank);   

    $("> .txt_pos").slideToggle('slow');                        
});

我如何让它选择每一个li,因为现在,它正在一次执行每个列表项。我正在尝试选择.pos.

4

2 回答 2

3

用于.children()选择孩子。

$(this).children('.txt_pos')

或者,如果您想选择li (您似乎在说两者),请使用.parent().

$(this).parent()
于 2012-06-14T12:10:05.203 回答
1
$(".list span.pos").each(function(i) {
        var newOne = i;
        newRank = getNth(newOne);

        $(this).children('.txt_pos').slideToggle('slow');
        $(this).text(newRank);   

        $(this).children('.txt_pos').slideToggle('slow');  //not sure why you're doing this again?
)};
于 2012-06-14T12:10:52.880 回答