私は3つの選択ボックスを持っています
いずれかの選択ボックスまたは2つの選択ボックスの数が2に等しい場合は、残りの選択ボックスを無効にする必要があります。
これがHTMLです
<ul>
<li><span>抹茶</span></br>
<select name="01345[]" class="cinch_set1">
<option value="0"></option>
<option value="1">1</option>
<option value="2">2</option>
</select><label> 箱</label></li>
<li><span>カフェラテ</span></br>
<select name="02345[]" class="cinch_set1">
<option value="0"></option>
<option value="1">1</option>
<option value="2">2</option>
</select><label> 箱</label></li>
<li><span>ストロベリー </span></br>
<select name="24190[]" class="cinch_set1">
<option value="0"></option>
<option value="1">1</option>
<option value="2">2</option>
</select><label> 箱</label></li>
</ul>
これがJqueryです
$('select').change(function(){
var disable = false;
first_sel = parseInt($('#cinchForm select.cinch_set1:eq(0)').val());
second_sel = parseInt($('#cinchForm select.cinch_set1:eq(1)').val());
third_sel = parseInt($('#cinchForm select.cinch_set1:eq(2)').val());
alert(first_sel+"-"+second_sel+"-"+third_sel);
count = first_sel+second_sel+third_sel;
if(count == 2){
if(first_sel == 0){
$('#cinchForm select.cinch_set1:eq(0)').attr('disabled', 'disabled');
$('#cinchForm select.cinch_set1:eq(1)').removeAttr('disabled');
$('#cinchForm select.cinch_set1:eq(2)').removeAttr('disabled');
}
else if(second_sel == 0){
$('#cinchForm select.cinch_set1:eq(1)').attr('disabled', 'disabled');
$('#cinchForm select.cinch_set1:eq(0)').removeAttr('disabled');
$('#cinchForm select.cinch_set1:eq(2)').removeAttr('disabled');
}
else if(third_sel == 0){
$('#cinchForm select.cinch_set1:eq(2)').attr('disabled', 'disabled');
$('#cinchForm select.cinch_set1:eq(1)').removeAttr('disabled');
$('#cinchForm select.cinch_set1:eq(0)').removeAttr('disabled');
}
}else{
$('#cinchForm select.cinch_set1:eq(0)').removeAttr('disabled');
$('#cinchForm select.cinch_set1:eq(1)').removeAttr('disabled');
$('#cinchForm select.cinch_set1:eq(2)').removeAttr('disabled');
}
});
2つの選択ボックスの数が2の場合、3番目の選択ボックスを無効にすることができます
しかし、単一の選択ボックスの数が2の場合、私のロジックは機能しません。