gpt4 book ai didi

jquery - 基于其他 选项

转载 作者:行者123 更新时间:2023-11-30 23:53:28 24 4
gpt4 key购买 nike

如果在其他选择中选择了确切的选项,如何禁用选择中的多个选项。我在此链接上找到了与我类似的问题的答案: http://jsfiddle.net/dZqEu/

接下来是 jQuery 代码:

$(this).siblings('select').children('option').each(function() {
if ( $(this).val() === value ) {
$(this).attr('disabled', true).siblings().removeAttr('disabled');
}

问题是这只适用于 2 个选择。我总共需要 3 个选择,这应该禁止选择选择中相同值的可能性。

此代码不适用于 3 个选择: http://jsfiddle.net/dZqEu/968/

提前交易

注意:

当 select1 设置为 1,select 2 设置为 2 时,我无法禁用 select3 中的值 1 和 2。它仅禁用选择 3 中的值 2...

最佳答案

试试这个:- http://jsfiddle.net/Z2yaG/

使用焦点获取上一个值并删除禁用的值。在你的 html 中,我为默认选项添加了值 -1 。

<option value="-1">No Match</option>

var prev = -1;
$("select").change(function () {
if ($(this).val() > -1) {
$("select").not(this).find("option[value=" + $(this).val() + "]").attr('disabled', 'disabled');
}
$("select").not(this).find("option[value=" + previous + "]").removeAttr('disabled');
}).focus(function () {
previous = $(this).val();
});

关于jquery - 基于其他 <select> 选项禁用 <select> 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16220296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com