How to get Selected Text from select2 when using <input>

前端 未结 9 1175
心在旅途
心在旅途 2020-12-12 23:38

I am using the select2 control, loading data via ajax. This requires the use of the tag.

Now, I want to retrieve the selecte

相关标签:
9条回答
  • 2020-12-13 00:12

    The code below also solves otherwise

    .on("change", function(e) {
    
      var lastValue = e.currentTarget.value;
      var lastText = e.currentTarget.textContent;
    
     });
    
    0 讨论(0)
  • 2020-12-13 00:14

    Also you can have the selected value using following code:

    alert("Selected option value is: "+$('#SelectelementId').select2("val"));
    
    0 讨论(0)
  • 2020-12-13 00:15

    This one is working fine using V 4.0.3

    var vv = $('.mySelect2');     
    var label = $(vv).children("option[value='"+$(vv).select2("val")+"']").first().html();
    console.log(label); 
    
    0 讨论(0)
提交回复
热议问题