自动完成的jQuery插件内调用函数 [英] Call function within autocomplete jQuery plugin
本文介绍了自动完成的jQuery插件内调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的自动完成
jQuery插件的工作,但我面临两个主要问题。
- 调用
自动完成
函数中的一个函数 - 获得
文本
的值与函数传递
HTML
<输入ID =txtDemo类型=文本/>
的js
$(#txtDemo)。自动完成({
来源:availableTags
});
这是我的功能,值为文本框的值
功能演示(值)
{
// code对数组的形式落后从code值
}
解决方案
您可以添加事件处理这样的
$('#txtDemo')。在('变化',函数(){
VAR值= $(本).VAL();
演示(值); //传递价值放慢参数
});//处理在这里
功能演示(值){
// code对数组的形式落后从code值
}
从您的意见:可以使用选择
选择(事件,UI)类型: autocompleteselect
当从菜单中选择一个项目时触发。默认操作
是与所选择的值来替换文本字段的值
项目。
块引用>$(#txtDemo)。自动完成({
来源:availableTags,
选择:函数(事件,UI){
演示(ui.item.value);
}});下面是样品 工作拨弄
希望您能理解。
I'm working with the
autocomplete
jQuery plugin, but I have faced two main problems.
- Calling a function within the
autocomplete
function- Getting the value of
textbox
to pass with functionHtml
<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 }
解决方案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.
这篇关于自动完成的jQuery插件内调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文