2017-05-23 4 views
0

私は、私が選択してボタンに入力にreadonlyreadonlyを適用しようとしています<section>jQueryのは、子要素の2種類

下の要素を切り替えるチェックボックスを持って、どのように私はjQueryのステートメントにそれをで達成できますか?

同じセレクタでjQueryをfindに2回作成するにはどうすればよいですか?

 $(this).parents('section') 
      .eq(0) 
      .find('input') <-- found all the inputs under <section> 
      .not('.cloud-media-toggle-inputs') 
      .prop('readonly', ! isChecked) 
      .find('select, button') <-- now I want to find all the <select>/<button> under <section> 
      .prop('disabled', ! isChecked); 
+0

を連鎖使用しないでくださいどのようにして、 "二度見つける"、意味ですか?すでにページのすべての要素が見つかりますが、多くの要素があります。セレクタが毎回何を変更しますか? – samiles

+0

最初の 'prop()'の後ろに 'end'を入れて' section'要素に選択を返します –

+0

@samiles質問のタイトルを再編集しました。 – Broshi

答えて

3

現在のチェーンの中で最も最近のフィルタリング処理を終了し、その前の状態にマッチした要素のセットを返す.end()

を使用する必要があります。

$(this).parents('section') 
     .eq(0) 
     .find('input') 
     .not('.cloud-media-toggle-inputs') 
     .prop('readonly', !isChecked) 
     .end() //<=========== 
     .find('select, button') 
     .prop('disabled', !isChecked); 

あるいは、

var sectionFirstChild = $(this).parents('section').eq(0); 
sectionFirstChild.find('input:not(.cloud-media-toggle-inputs)').prop('readonly', !isChecked); 
sectionFirstChild.find('select, button').prop('disabled', !isChecked); 
+0

は入力用に機能し、選択/ボタン用に機能しません。 – Broshi

+0

@Broshi、HTMLを共有できますか? – Satpal

+0

実際にはHTMLのバックエンドページの一部ではありません...私は再びそれに取り組むか、ちょうど二重jqueryの参照をします – Broshi