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

Call function within autocomplete jQuery plugin

本文关键字:插件 函数 jQuery 调用      更新时间:2023-09-26

我正在使用autocompletejQuery插件,但我面临两个主要问题。

  1. 调用autocomplete函数中的函数
  2. 获取要与函数一起传递的textbox的值

Html

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

Js

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

这是我的函数,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

选择(事件,ui)类型:自动完成选择

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

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

这是样品工作小提琴

希望你能理解。