次のコードがあります。
$(document).ready(function(){
$("[name=q58]").each(function (i) {
$(this).click(function () {
var selection = $(this).val();
alert('Q58 Value = '+selection)
if (selection == '1') {
$("#region").show();
$("[name=q59]").each(function (i) {
$(this).click(function () {
var selection = $(this).val();
alert('Q59 Value = '+selection)
if (selection == '1') {
$("#location").show();
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#east, #north, #scotland, #southeast, #southwest").hide();
$("#central").show();
}
else if (selection == '2') {
$("#location").show();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #north, #scotland, #southeast, #southwest").hide();
$("#east").show();
}
else if (selection == '3') {
$("#location").show();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #scotland, #southeast, #southwest").hide();
$("#north").show();
}
else if (selection == '4') {
$("#location").show();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #north, #southeast, #southwest").hide();
$("#scotland").show();
}
else if (selection == '5') {
$("#location").show();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #north, #scotland, #southwest").hide();
$("#southeast").show();
}
else if (selection == '6') {
$("#location").show();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #north, #scotland, #southeast").hide();
$("#southwest").show();
}
else {
$("#location").hide();
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #north, #scotland, #southeast, #southwest").hide();
}
});
});
}
else if (selection == '10') {
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#central, #east, #north, #scotland, #southeast, #southwest").hide();
$("#location").hide();
$("#region").show();
}
else {
$("input:radio[name^='q59']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='central-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='east-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='north-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='scotland-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southeast-']").each(function(i) {
this.checked = false;
});
$("input:radio[name^='southwest-']").each(function(i) {
this.checked = false;
});
$("#region").hide();
$("#location").hide();
$("#central").hide();
}
});
});
});
JsFiddle で動作する、または動作しない例: JsFiddle の例を参照してください: http://jsfiddle.net/ExPUu/1/
次の奇妙な動作が発生します。
ユーザーが を選択すると、表示され、 または または のいずれかをAftersales
選択q59
できCentral
ます。これはうまくいきます。East
q60
ユーザーがBus, Coach and Engines
それ以上のオプションを取得しないことを選択した場合、再び正常に動作します。
奇妙な動作は、ユーザーがSales
これを選択した場合に選択すると、選択できるはずです。Central
またはEast
、クリックSales
して他に何もない場合、これは正常に機能します。 しかし、彼らが選択Aftersales
してから気が変わって選択してから、またはSales
いずれかを選択しCentral
た場合East
、それは表示されますが、表示さq60
れるべきではありません。
私は自分のjQueryコードを調べてきましたが、どこが間違っているのかわかりません。それともこれは異常ですか?