1
var obj = $("form select");
alert(obj.find(":selected:eq(0)").val()); // works
alert(obj.find(":selected:eq(1)").val()); // Does Not Work

如何使用缓存的 obj 从其余选择元素中找到选定的选项?

var n = 2;
var nthSelected = $(":selected",obj[n]); //Seems to work

也可以使用 .filter() 访问缓存对象的各个元素,如下所示:

alert(obj.filter(":eq(1)").val());
4

2 回答 2

0
var selectedValues = [];

obj.each(function() {
  var selected = $(':selected', this).val();
  selectedValues.push(selected);
});

//now you have an array of all the selected values.  :)
于 2011-05-03T16:31:35.077 回答
0

像这样的东西应该工作:

var selects = $('form select');
var selected = $(':selected', selects);
于 2011-05-03T16:31:39.593 回答