jquery autocomplete get selected item text

后端 未结 4 577
傲寒
傲寒 2021-02-07 04:22

I am wondering how to grab the selected item\'s text value on jquery autocomplete.

I have initialised jquery as following :

$(document).ready(function ()         


        
4条回答
  •  孤独总比滥情好
    2021-02-07 05:12

    You don't need to apply an anonymous function as a wrap, you can directly pass the function ref.

    $(document).ready(function (){
       $("input#autocomplete").autocomplete({
            source: postcodelist,
            select: AutoCompleteSelectHandler
        });
    });
    

    Within that method, you can either access this or event.target to get the current value, both values are referencing the input element:

    function AutoCompleteSelectHandler(event, ui) {
        alert( $(event.target).val() );
        alert( $(this).val() );
    
        // alert( this.value );
    }
    

提交回复
热议问题