如何从jQuery的下拉列表中获取所选文本(而不是所选值)?


当前回答

$("#dropdownid").change(function(el) {
    console.log(el.value);
});

或者你可以用这个

$("#dropdownid").change(function() {
    console.log($(this).val());
});

其他回答

var someName = "Test";

$("#<%= ddltest.ClientID %>").each(function () {
    $('option', this).each(function () {
        if ($(this).text().toLowerCase() == someName) {
            $(this).attr('selected', 'selected')
        };
    });
});

这将帮助你找到正确的方向。如果您需要进一步的帮助,请告诉我,上面的代码经过了充分测试。

$("option:selected", $("#TipoRecorde")).text()

$(“#DropDownID”).val()将给出选定的索引值。

对于多选:

$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }

如果要将结果作为列表,请使用:

x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})