我有三个下拉选择列表,当从列表之一中选择一个值时,我希望其他两个显示为灰色且不活动。我正在尝试的每个选择列表周围都有id包装器,但是由于我是jquery的新手,所以我的步伐还不是很远。

最佳答案

这样的事情应该起作用:

$(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');
  });
});

10-06 04:44