如何从所有选定的下拉列表项中获取值

时间:2013-07-21 14:47:16

标签: javascript jquery

<table id="tb_Answers">
    <tbody>
        <tr>
            <td>
                <select class="ddl_NextQuestion" name="_ctl0">
                    <option value="0">End</option>
                    <option value="95">ans 1</option>
                    <option value="96">ans 2</option>
                    <option value="97">ans 3</option>
                    <option value="98">ans 4</option>
                </select>
            </td>
            <select class="ddl_NextQuestion" runat="server">
                </td>
                <td>
        </tr>
        <select class="ddl_NextQuestion" runat="server">
            </td>
            <td>
                </tr>
    </tbody>
</table>

我来到这里3 ddl我在其中每一个中选择了项目我需要从所有选定的ddl项目中获取所有值,并且类“ddl_nextQuestion”有些人认为这样

var arrAns= $.map($('select.ddl_NextQuestion.options[ddl_NextQuestions.selectedIndex].value'), function(el) {return el.value;});

但这不起作用......它适用于输入

var arrUrls = $.map($('input.txt_Url'), function(el) {return el.value;});

但没有下拉列表

2 个答案:

答案 0 :(得分:4)

几乎:

var arrSelectedAnswers = $('.ddl_NextQuestion').map(function () {
    return this.value;
}).get();

Demo.

答案 1 :(得分:2)

工作演示http://jsfiddle.net/zsGWY/2

var x ='';
$(".ddl_NextQuestion").each(function(){
   x+=$(this).val()+',';
});
alert(x.slice(0,-1));