如何获取输入元素触发jQuery自动完成小部件? [英] How to get the input element triggering the jQuery autocomplete widget?
本文介绍了如何获取输入元素触发jQuery自动完成小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个使用jQuery自动完成功能增强的输入字段.触发选择事件时如何获取相应的输入字段?
I have several input fields that are enhanced with jQuery auto-complete functionality. How to get the corresponding input field when a select event is triggered?
<input name="1" value="">
<input name="2" value="">
<input name="3" value="">
$('input[type=text]').autocomplete({
source: 'suggestions.php',
select: function(event, ui) {
// here I need the input element that have triggered the event
}
});
推荐答案
尝试使用$(this)
$('input[type=text]').autocomplete({
source: 'suggestions.php',
select: function(event, ui) {
// here I need the input element that have triggered the event
alert($(this).attr('name'));
}
});
这篇关于如何获取输入元素触发jQuery自动完成小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文