自动完成后触发 Onchange 事件 [英] Fire Onchange event after AutoComplete
问题描述
我正在尝试一次执行 Autocomplete 和 onchange 事件.
意思是:我想在自动完成文本框中触发 onchange 事件.当我从键盘在文本框中写一些东西并在文本框外单击然后 onchange 事件触发但是当我从自动建议名称中选择某些内容时 onchange 事件没有触发.
我的 HTML 代码
人名:<input id="txt0" type="text" onchange="SaveData('txt0')" class="userSearch" placeholder="Helped Person"/>
JavaScript 代码
function AutoComplete() {//自动完成添加到文本框.$('.userSearch').自动完成({来源:功能(请求,响应){$.ajax({url: "CTC.aspx/GetMemberName",数据:{'prefixText':'"+ request.term +'}",数据类型:json",类型:POST",contentType: "application/json; charset=utf-8",成功:功能(数据){响应(数据.d)},错误:函数(XMLHttpRequest,textStatus,errorThrown){alert('自动完成时出错');}});},最小长度:1});}函数 SaveData(textBoxId) {警报(文本框Id);}
我想在从自动完成中选择后触发 onchange 事件.
请帮忙
提前致谢.
您可以使用自动完成小部件上的更改事件来实现此目的.http://api.jqueryui.com/autocomplete/#event-change
例如:
function AutoComplete() {//自动完成添加到文本框.$('.userSearch').自动完成({来源:功能(请求,响应){//你的ajax代码},最小长度:1,更改:函数(事件,用户界面){ SaveData();}});}
I am trying to do Autocomplete and onchange event at a time.
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.
My 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);
}
I want to fire the onchange event after selected from autocomplete.
Please Help
Thanks in advance.
You can use the change event on the autocomplete widget to achieve this. http://api.jqueryui.com/autocomplete/#event-change
For example:
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屋!