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現在、すべてのリスト項目を1回実行しているため、それぞれを選択するにはどうすればよいですか。の子を選択しようとしています.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 に答える