自动完成后发出onChange事件 [英] Fire Onchange event after AutoComplete
问题描述
我试图做自动完成和onchange事件在同一时间。
I am trying to do Autocomplete and onchange event at a time.
表示:我想火的自动完成文本框onchange事件。
当我写的键盘在一个文本框的东西,点击文本框,然后onchange事件触发外,但是当我在选择东西从自动提示名称onchange事件不点火。
Means:I want to fire onchange event in a autocomplete textbox. When i write something in the a textbox from keyboard and click outside the textbox then onchange event firing but when i select something in the from the auto suggest names onchange event is not firing.
我的HTML code
<div style="width: 34%">
Person Name:<input id="txt0" type="text" onchange="SaveData('txt0')" class="userSearch" placeholder="Helped Person" />
</div>
JavaScript的code
function AutoComplete() {
//Autocomplete added to the textbox.
$('.userSearch').autocomplete({
source: function (request, response) {
$.ajax({
url: "CTC.aspx/GetMemberName",
data: "{ 'prefixText': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response(data.d)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('Error occured while autocomplete');
}
});
},
minLength: 1
});
}
function SaveData(textBoxId) {
alert(textBoxId);
}
我想从自动完成选择之后触发onchange事件。
I want to fire the onchange event after selected from autocomplete.
请帮助
先谢谢了。
推荐答案
您可以使用自动完成插件的更改事件来实现这一目标。
<一href=\"http://api.jqueryui.com/autocomplete/#event-change\">http://api.jqueryui.com/autocomplete/#event-change
You can use the change event on the autocomplete widget to achieve this. http://api.jqueryui.com/autocomplete/#event-change
例如:
function AutoComplete() {
//Autocomplete added to the textbox.
$('.userSearch').autocomplete({
source: function (request, response) {
// your ajax code
},
minLength: 1,
change: function (event, ui) { SaveData(); }
});
}
这篇关于自动完成后发出onChange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!