简体   繁体   中英

Javascript/JQuery how to get text from multiple select input

I want to return selected text, instead of value. I know how to return value:

$("#myid").multiselect("getChecked").map(function(){
     return this.value
}).get().join(",");

but I dont know how to get text. I tried in map function this.text, this.val() and so on, but none of that is working. Please help..

The multiSelect I could find uses TITLE to hold the text value

DEMO

$( "#myid" ).multiselect("getChecked").map(function(input){
   return input.title;
}).get().join(",");

DOM Element object doesn't have text property, you can use textContent property of DOM Element object or jQuery text method:

var texts = $("#myid").multiselect("getChecked").map(function(){
    return this.textContent || this.innerText;
    // return $(this).text();
}).get().join(",");

There is jQuery method .html() method to get the innerHTML.

        $("#myid").multiselect("getChecked").map(function(){
           return this.html();
}).get().join(",");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM