次の表があります。このテーブルでは、次の形式の行を動的に追加しました。
<tr class="conditionalRow">
<td class="logicalData">
<select oldvalue="AND" class="logicSelectionMenu">
<option value="AND">AND</option>
<option value="AND (">AND (</option>
<option value="OR">OR </option>
<option value="OR (">OR (</option>
<option value=")">)</option>
</select>
</td>
<td class="fieldData">
<p>Other Data that you don't need to worry about</p>
</td>
<td class="conditionData">
<p>Other Data that you don't need to worry about</p>
</td>
<td class="compareData">
<p>Other Data that you don't need to worry about</p>
</td>
<td>
<button class="removeConditionButton" type="button"> - </button>
</td>
</tr>
次のjQueryセレクターを使用してonchangeイベントを処理します。
$(document).ready(function() {
$(".logicSelectionMenu").change(function() {
var row = $(this).closest("tr");
updateLogicMenu(row);
});
$(".logicSelectionMenu").focus(function() {
$(this).attr("oldValue",$(this).val());
});
});
function updateLogicMenu(inRow) {
var selectedVal = $(inRow).find(".logicSelectionMenu").attr("value");
var oldVal = $(inRow).find(".logicSelectionMenu").attr("oldValue");
/* -=> VERY IMPORTANT LINE BELOW!!! <=- */
// alert("Hi, I cause a time delay");
if (selectedVal == ")") {
// clears cell contents if ")" is choosen by user
$(inRow).find(".fieldSelectionMenu" ).css("visibility","hidden").html("");
$(inRow).find(".conditionSelectionMenu").css("visibility","hidden").html("");
$(inRow).find(".compareData" ).css("visibility","hidden").html("");
}
else if(oldVal == ")" || oldVal === undefined) {
// regenerates cell contents when user changes selection from ")" to another
alert("regenerating");
$(inRow).find(".fieldSelectionMenu").css("visibility","visible").html(getFieldSelectionOptions());
$(inRow).find(".conditionSelectionMenu").css("visibility","visible");
$(inRow).find(".compareSelectionMenu").css("visibility","visible");
updateFieldMenu(inRow); // function regenerates the next cell contents
// and calls another function
// which regenerates the next cell contents,
// and chains on and on ... etc
}
else { ; } // no action is needed,no clearing or regeneration
}
問題は、ドロップダウンメニューから[)]オプションを選択してから、別のオプションを選択した場合です。これで、ページは期待どおりに動作します。
非常に重要な行がコメントアウトされていない場合、両方のアラートボックスがポップアップし、「時間遅延が発生します」と「再生中」と表示され、次のセルの内容が期待どおりに再生されます。
非常に重要な行がコメント化されている場合、JavaScriptはelse句を入力せず、次のセルの内容は再生成されません。
このアラートボックスが原因でページが期待どおりに動作するのに、ページが予期しない動作をする原因は何ですか?ユーザーが[OK]ボタンをクリックするのは時間の遅れですか?このアラートボックスを本番ページに表示したくないので、アラートボックスの有無にかかわらず、ページを同じように動作させるにはどうすればよいですか?