自动完成jQuery插件中的调用函数

我正在使用autocomplete jQuery插件,但我遇到了两个主要问题。

  1. autocompletefunction中调用一个函数
  2. 获取textbox的值以通过函数传递

HTML

  

JS

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

这是我的function ,Value是textbox

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

您可以添加这样的事件处理程序

 $('#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 } 

从你的评论:可能使用select

select(event,ui)类型: autocompleteselect

从菜单中选择项目时触发。 默认操作是将文本字段的值替换为所选项的值。

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

这是样本工作小提琴

希望你能理解。