jquerymultiselect:如何知道选择/取消选择了哪个值
我有多选下拉列表。无论何时有选择或取消选择,我都需要获取值。 我正在使用change event,但正在努力获取选择/取消选择的选项jquerymultiselect:如何知道选择/取消选择了哪个值,jquery,multi-select,Jquery,Multi Select,我有多选下拉列表。无论何时有选择或取消选择,我都需要获取值。 我正在使用change event,但正在努力获取选择/取消选择的选项 //all options var all=[]; $('#multiple').each(function(i, selected){ all[i] = $(selected).text(); }); //selected options var foo = []; $('#multiple :selected').each(functio
//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
数组中是未选择的值
$('#selectId').on('change',function(){
console.log($(this).val());// this will give you an array
});
我要选择或选择的选项,$(“#城市选项:选定”)。attr(“值”)返回所有选定值,而不是当前值。通过此选项,您将获得选定选项。此选项返回所有选定值,并且不回答有关选定值和取消选定值的原始问题