私はこれをしばらくいじっていましたが、理解できません。
すぐに、特定のページ/セグメントのコンテンツが適切かどうか、または適切な形式であるかどうかを確認する必要があります。
条件
- 少なくとも 1 つの要素 .box が必要です
- 各要素 .box には、クラス .question の 1 つ以上の div 要素が含まれている必要があります
- 各 .questions には 2 つ以上の :radio ボタンが含まれている必要があります
これで問題ありません (残りの要素と混同しないでください。実際の例にすぎません)。
<div class="box" type="1">
<div class="question">
<div class="answers">
<table>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
</table>
</div>
</div>
</div>
<div class="box" type="1">
<div class="question">
<div class="answers">
<table>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
</table>
</div>
</div>
</div>
ただし、1 つの .question div (最後の 1 つ) には :radio ボタンが 1 つしかないため、有効ではないため、これは失敗します。
<div class="box" type="1">
<div class="question">
<div class="answers">
<table>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
</table>
</div>
</div>
</div>
<div class="box" type="1">
<div class="question">
<div class="answers">
<table>
<tr>
<td><input type="radio" name="someName" value="1" /><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
<tr>
<td><label>Some Label Here..</label></td>
<feedback>Question response 1.<strong>some quoted content in bold</strong></feedback>
</tr>
</table>
</div>
</div>
</div>
私はこのようなことを試しましたが、うまくいきません...:
if($('.box').filter(function() { var self = $(this); return self.find('.question').length == 1 && self.find('.question :radio' .length > 1; }).length > 0) { alert('NO') } else { $('.box:first').fadeIn(1000); }
この:
if ($('.box').length) { $('.box').each(function(){ if ($(".question", this).length) { $(".question"). each(function(){ if($(':radio', this).length > 1) alert('ok') }); }
}); } else { アラート('!ok'); };