How to get the input element triggering the jQuery autocomplete widget?

后端 未结 5 2033
温柔的废话
温柔的废话 2021-01-01 14:18

I have several input fields that are enhanced with jQuery auto-complete functionality. How to get the corresponding input field when a select event is triggered?

<         


        
5条回答
  •  [愿得一人]
    2021-01-01 15:17

    Try using $(this)

    $('input[type=text]').autocomplete({
        source: 'suggestions.php',
        select: function(event, ui) {
            // here I need the input element that have triggered the event
            alert($(this).attr('name'));
        }
    });
    

提交回复
热议问题