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());
答案 0 :(得分:0)
var selectedValues = [];
obj.each(function() {
var selected = $(':selected', this).val();
selectedValues.push(selected);
});
//now you have an array of all the selected values. :)
答案 1 :(得分:0)
这样的事情应该有效:
var selects = $('form select');
var selected = $(':selected', selects);