私は次のhtmlを持っています:
<div id="segmenter">
<div id="variable" name="Zone">
<h3>Zona</h3>
<ul>
<li><input id="category" type="checkbox" value="Center">Center</li>
<li><input id="category" type="checkbox" value="East">East</li>
<li><input id="category" type="checkbox" value="South">South</li>
</ul>
</div>
<div id="variable" name="Type of">
<h3>Tipo de Restaurante</h3>
<ul>
<li><input id="category" type="checkbox" value="Freestander">Freestander</li>
<li><input id="category" type="checkbox" value="Instore">Instore</li>
<li><input id="category" type="checkbox" value="Mall">Mall</li>
</ul>
</div>
</div>
最初に、IDが「変数」のセグメンターのすべてのdiv子を反復処理し、次に、各子「変数」のIDが「カテゴリー」のすべての入力を反復処理します。
Chrome開発ツールの使用:
と:
$("#segmenter > #variable")
私はすべてのdiv変数を取得します:[<div id="variable" name="Zona">…</div>, <div id="variable" name="Tipo de Restaurante">…</div>]
ここから、私が試したすべてが機能しません。たとえば、次のようになります。
$("#segmenter > #variable").find("#category");
私は4つの入力「カテゴリ」しか取得しません:[<input id="category" type="checkbox" value="Centro">, <input id="category" type="checkbox" value="Freestander">, <input id="category" type="checkbox" value="Instore">, <input id="category" type="checkbox" value="Mall">]
理由はわかりません。必要なのは、次のような反復です。
var oVariables = $("#segmenter > #variable");
$.each(oVariables, function(){
var oCategory = $(this).find("#category").text();//in the first call for div-name="zone", only have the first input-value"center"
//Iterate Again
//get checked values, etc
});
どうもありがとう。