what event is used in order to show an alert message on selecting a value in the textbox

后端 未结 1 414
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 10:36

I am using autocomplete api of jquery in order to fetch the name from the database.But i want to show an alert message on selecting a name from the textbox displayed.I will show

相关标签:
1条回答
  • 2021-01-28 11:11

    If you're using devbridge's Ajax Autocomplete for jQuery:

    Use a settings object to set the instance up, with your URL and an event handler on selecting a value:

    $(document).ready(function() {
      var selectedValue = '';
      $( '#country' ).autocomplete({
        serviceUrl: 'list.jsp',
        onSelect: function(suggestion) {
          selectedValue = suggestion.value;
          alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
        }
      });
    });
    

    If you're using jQuery UI's Autocomplete:

    Handle the autocompleteselect event rather than the change event and access the value of the selected item by using ui.item.value rather than .val(), where ui is the second argument provided in the event handler function.

    $(document).ready(function() {
       var selectedValue = '';
       $( '#country' ).autocomplete({
           source: 'list.jsp',
           select: function(e, ui) {
             selectedValue = ui.item.value;
             alert(selectedValue);
           }
       });
     });
    

    See https://api.jqueryui.com/autocomplete/#event-select

    0 讨论(0)
提交回复
热议问题