2

3 つのドロップダウン選択リストがあり、リストの 1 つの値が選択されている場合、他の 2 つをグレー表示して非アクティブにします。私が実験している各選択リストの周りに id ラッパーがありますが、私は jquery を初めて使用するため、あまりうまくいきません。

4

4 に答える 4

4

このようなものが動作するはずです:

$(function() {
  var $selects = $('#select1, #select2, #select3');
  $selects.change(function() {
    // disabled the other two
    $selects.not(this).attr('disabled', 'disabled');
  });
});


更新版:

$(function() {
  var $selects = $('#select1, #select2, #select3');
  $selects.change(function() {
    // disable or enable the other two
    $selects.not(this).attr('disabled', $(this).val() === '' ? '' : 'disabled');
  });
});
于 2010-08-10T22:50:57.440 に答える
0

次のようなことができます。

$('#wrappers').change(function(){
  $('#select1').attr('disabled', true);
  $('#select2').attr('disabled', true);
});

select 要素の ID はどこwrappersにあり、値を選択すると他の 2 つの ID が無効になりselect1select2それぞれ次のようになります。

<select id="wrappers">.........
<select id="select1">.........
<select id="select2">.........

これが実際の例です

于 2010-08-10T22:42:36.877 に答える
0

3 つあると仮定します。3 つのうちのいずれかが選択されている場合、他の 2 つを無効にする必要があります。

function toggleOthers(x) {
var select = new Array('#wrapper1','#wrapper2','#wrapper3');

for (int i = 0; i < select.length; i++ )
    if ($(x).attr('id')!=select[i])
        $(x).attr('disabled','disable');
}

HTML: <select onchange='toggleOthers(this);' id='wrapper1'> etc...

于 2010-08-10T22:48:53.530 に答える
0

#wrapper の ID を持つ div ラッパーを選択した場合

$('#wrapper select').each(function(i,select){
   $(select).change(function(){
        $(this).attr('class','enabled').siblings().attr('class','disabled');
    })
})
于 2010-08-10T23:04:29.043 に答える