jquery – 根据其他列表中的选择禁用下拉列表中的选项

我有以下代码
$('select').on('change',function(){
    $('select option').prop("disabled",false);
    $("select").not(this).find("option[value="+ $(this).val() +     "]").prop('disabled',true);
});

然后有3个下拉列表

<select name="Vote1" id="Vote1">
<option value="player1">Player1</option>
<option value="player2">Player2</option>
<option value="player3">Player3</option>
<option value="player4">Player3</option>
</select>
<select name="Vote2" id="Vote2">
<option value="player1">Player1</option>
<option value="player2">Player2</option>
<option value="player3">Player3</option>
<option value="player4">Player3</option>
</select>
<select name="Vote3" id="Vote3">
<option value="player1">Player1</option>
<option value="player2">Player2</option>
<option value="player3">Player3</option>
<option value="player4">Player3</option>
</select>

使用我的代码,当您选择1项时,它会在其他两个迭代的下拉列表中禁用它,但是如果我再单击另一个列表中的另一个选项,则会启用其他选项中的选项.

我希望能够在一个下拉列表中选择该选项,并在所有其他下拉列表中保持禁用状态,直到取消选中该选项.

这可能吗?

JS fiddle

解决方法

这与您已经拥有的几乎完全相同,除了每次更改时循环遍历每个选择,并禁用在其他选择中选择的选项:
var $selects = $('select');

$selects.on('change',function() {

    // enable all options
    $selects.find('option').prop('disabled',false);

    // loop over each select,use its value to 
    // disable the options in the other selects
    $selects.each(function() {
       $selects.not(this)
               .find('option[value="' + this.value + '"]')
               .prop('disabled',true); 
    });

});

Here’s a fiddle

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...