gpt4 book ai didi

Jquery多选: How to know which value was selected/deselected

转载 作者:行者123 更新时间:2023-11-30 23:43:10 25 4
gpt4 key购买 nike

我有多选下拉菜单。每当有选择或取消选择时,我都需要获取该值。我正在使用更改事件,但很难确定选择/取消选择了哪个选项。

最佳答案

//all options

var all=[];
$('#multiple').each(function(i, selected){
all[i] = $(selected).text();
});

//selected options
var foo = [];
$('#multiple :selected').each(function(i, selected){
foo[i] = $(selected).text();
});

// unselected options
var de= $.grep(all, function(element) {
return $.inArray(element, foo) !== -1;
});

foo 数组中是选定的值

de数组中是未选择的值

关于Jquery多选: How to know which value was selected/deselected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18627643/

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