I have Multiselect dropdown. Whenever there is a select or deselect, I need to get the value.
I am using change event, but struggling to get which option was selected/deselected.
解决方案//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;
});
In the foo array are the selected values
In the de array are the unselected values