1

jqueryでこれらのいずれかを行うにはどうすればよいですか?

  1. n番目の子のn番目の子
  2. n 番目の子の最初の子
  3. 画像である n 番目の子の子孫 (子または孫)

編集:変数を使用して、このように「子」にアクセスしています

var number = ( ... code ...) ;
.... eq(number)

だから私は次のようなことはできません

$('li:nth-child(2) li:nth-child(2)')
4

1 に答える 1

6

2つを組み合わせる?

//1
$(":nth-child(2) :nth-child(3)")
//2
$(":nth-child(2) :first-child")
//3
$(":nth-child(2) img")

CSS スタイルシートの場合と同じ方法で行います。

var number = 2;
//1
$(":nth-child(" + number + ") :nth-child(" + number + ")")
//2
$(":nth-child(" + number + ") :first-child")
//3
$(":nth-child(" + number + ") img")
于 2012-06-26T19:31:26.003 に答える