--フィドル--
私は、ウィザードのように機能するフォームを設計しており、ユーザーに各入力を案内し、すべての入力が処理されるまで続行できないようにしています。
現在の行のすべての入力が入力またはチェックされている場合にのみ、テーブルの次の行を表示したいと考えています。行には、任意の数のテキスト入力、チェックボックス、またはラジオ グループを含めることができます。
これが私の現在のコードです:
<table>
<tr>
<td><input type="text"></td>
<td><input type="radio"></td>
</tr>
<tr style="display:none">
<td><input type='radio'></td>
<td><input type='checkbox'></td>
</tr>
<tr style="display:none">
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
</table>
function refreshCascadingLists() {
// Get an array of tr's
// Loop thorugh each and see if it should be shown based on it's predecessors status
var prevHadUnselected = false;
$("table tr").next("tr").each(function(curIdx, curEntity) {
if (prevHadUnselected) {
$(this).fadeOut();
} else {
$(this).fadeIn();
}
prevHadUnselected = false;
$(this).find(":input").each(function(curSelIdx, curSelEntity) {
if ($(curSelEntity).val() == "" && $(curSelEntity).not(":checked"))
prevHadUnselected = true;
});
});
}
$(document).ready(function() {
$(":input").bind('keyup change', function() {
refreshCascadingLists();
});
});
これにより、ユーザーが最初の行のテキスト ボックスに入力すると次の行が表示されますが、ラジオ ボタンもオンにする必要があります。さらに、次の行だけでなく、テーブル内のすべての行を表示しています。