从select2输入获取当前搜索词

Bro*_*mer 0 jquery jquery-select2

我想从select2输入中获取当前搜索项值(即使它不匹配).

<div class="select2-container select2-container-multi form-control" id="s2id_author">
    <ul class="select2-choices">  
        <li class="select2-search-field">    
            <label for="s2id_autogen1" class="select2-offscreen"></label>    
            <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" id="s2id_autogen1" placeholder="" style="width: 34px;" aria-activedescendant="select2-result-label-2">  
        </li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

Dan*_*pos 8

这个在4.0+以上为我工作

var nome = $("#select2_id").data('select2').$dropdown.find("input").val();
Run Code Online (Sandbox Code Playgroud)


Beg*_*ner 5

你可以试试这个:

$(selector)
  .data("select2")
  .search[0]
  .value;
Run Code Online (Sandbox Code Playgroud)