jQuery 选择 - 获取(多个)选定的标签(不是值)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19465800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:02:28  来源:igfitidea点击:

jQuery Chosen - get (multiple) selected labels (not the value)

jqueryjquery-chosen

提问by COBIZ webdevelopment

How to get the selectedoption's textfrom the Chosenselect? So not just the .val()but the option label/text

如何从Chosen 中获取selected选项的文本?所以不只是选项select.val()label/text

回答by 123

You can simply use this to get the label.

您可以简单地使用它来获取标签。

$('.result-selected').html() 

or

或者

$('.options option:selected').html() 

回答by COBIZ webdevelopment

Used: $("#list option[value='"+id+"']").text();To retrieve the labelof the selectedvalue

使用: $("#list option[value='"+id+"']").text();要检索label的的selected价值

回答by Adesh M

$("#objId option :selected").text();

Above jQuerystatement should do it for.

上面的jQuery语句应该这样做。

回答by Mohamed Sabirulla

//Below code return name of the drop downn

//下面的代码返回下拉列表的名称

$('#availableRevisionBatch option:selected').text() 

//Below code return value of the drop downn

//下面的代码返回下拉的值n

$('#availableRevisionBatch option:selected').val() 

回答by Sinan ?ALI?KAN

You can check this for single select.

您可以检查此项以进行单选。

<select class="chzn-select" id="CHSNID" onchange="alert($('#CHSNID_chzn a span').text())">

Or

或者

$(function(){
     $('#CHSNID').change(function(){
     var text = $('#CHSNID_chzn a span').text();
     console.log(text);
   }); 
});

回答by kravits88

To get text values for multiple select:

要获取多个选择的文本值:

<select id="sTags" class="chosen" multiple />

Jquery:

查询:

    $.map($("#sTags_chosen").find(".search-choice span"), function (option) {
        return $(option).text()
    });

回答by Daniel

The only way that work for me, was doing something like this:

对我有用的唯一方法是做这样的事情:

var options = $("#ddl option:selected");

var values = $.map(options, function (option) {
    return option.text;
});

Where values is an array.

其中 values 是一个数组。

Hope that it helps...

希望它有帮助...

回答by hayoeu

The below will get the label & here is a JSFiddle showing how to get the chosen dropdown's value or label field using the latest chosen jquery plug-in version 1.4.2. https://jsfiddle.net/hayoeu/4usazfdm/2/

下面将获取标签 & 这里是一个 JSFiddle,显示如何使用最新选择的 jquery 插件版本 1.4.2 获取所选下拉列表的值或标签字段。https://jsfiddle.net/hayoeu/4usazfdm/2/

$(".chzn-select option:selected").text();

回答by vivek takrani

none of the above answers worked for me and so after searching a lot finally got the answer to retrieve the "label" value of the selected element

以上答案都不适合我,因此经过大量搜索后终于得到了检索所选元素的“标签”值的答案

$("#your_select_id option:selected").attr('label');