问题
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 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