Call function within autocomplete jQuery plugin [closed]

耗尽温柔 提交于 2019-12-23 03:33:14

问题


I'm working with the autocomplete jQuery plugin, but I have faced two main problems.

  1. Calling a function within the autocomplete function
  2. Getting the value of textbox to pass with function

Html

<input id="txtDemo" type="text" />

Js

$("#txtDemo").autocomplete({
   source: availableTags
});

This is my function, Value is value of textbox

function Demo (value)
{
//code for getting value from code behind in the form of array
}

回答1:


You can add an event handler like this

$('#txtDemo').on('change', function(){
 var value = $(this).val();
 Demo (value); //pass the value as paramter
});

//Handle it here
function Demo (value) {
 //code for getting value from code behind in the form of array
}

From your comments: Possible using select

select( event, ui )Type: autocompleteselect

Triggered when an item is selected from the menu. The default action is to replace the text field's value with the value of the selected item.

$("#txtDemo").autocomplete({   
   source: availableTags,
   select: function( event, ui ) {
            demo(ui.item.value);          
      }

});

Here is sample working fiddle

Hope you can understand.



来源:https://stackoverflow.com/questions/18510926/call-function-within-autocomplete-jquery-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!