2

我有一些组合框,需要选定组合框的值。

我这样做:
但不工作。

var check_combo_box_values = $('#combos .combo').filter(function() { 
                return this.selectedIndex === 0;
                }).map(function () 
                {
                    return $('option:selected', this).map(function() {
                    return parseInt(this.value);
                    }).get();
                }).get();

另一方面,这是有效的:

var combo_box_values = $('#combos .combo').filter(function() {
                return this.selectedIndex === 0;
                }).map(function () 
                {
                    return $('option:not(:selected)', this).map(function() {
                    return parseInt(this.value);
                    }).get();
                }).get();

我有第二个代码,并试图使其适应我的需要,第一次尝试出现了。似乎不正确(:错误在哪里?

干杯

4

1 回答 1

0

You're using .filter() this method filters the results from your first selection $('#combos .combo'). So from your filter you're only receiving the comboboxes that have their first option selected. If you wish to get all selected values of all comboboxes you need to remove the filter or reverse the filter in case you don't want those that have their first element selected (which is mostly a default element)

If you just generally wish all selected options you can just use this: http://jsfiddle.net/nqTNH/

于 2012-12-04T11:40:45.163 回答