根据以下multiselect我需要获取从一页上的许多多重下拉列表中选择的选定值。我有一个通用事件处理程序设置,如果在页面上的任何多选上单击一个选择,则会触发一个公共(public)事件。两个问题:
1) 我如何知道事件来自哪个 muliselect (#Name)? 2) 如果事件来自同一个容器,如何从多选单击函数中获取 .val() ?
// generic event for all multiselect
$("select").multiselect({
click: function (event, ui) {
// 1 - What multiselect container?
// 2- Get the list of selected values
var vals = $('#CNames').val(); // This doesn't work if the event was fired from #CNames..null.
var vals = $('#CAreas').val(); // This works if the event came from #CNames.
最佳答案
您可能可以获得单击的选择的 ID
var name = $(this).attr('id');
以及所有选择的值
var values = [];
$('select').each(function() {
$.merge(values, $(this).val());
});
或当前选择
var values = $(this).val();
关于javascript - 获取所有选定的值()'s from a multiselect container per it'自己点击:event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8442246/