在 jQuery 组合框上选择下拉项后触发事件
Trigger event once dropdown item is selected on jQuery combobox
我正在使用jQuery UI库中的自动完成组合框来创建几个也接受下拉列表的文本字段 - 基本上是混合文本/下拉列表输入。我对其进行了自定义,因此它也接受自由文本输入,而不仅仅是下拉数组中的项目。
当用户从下拉列表中选择一个项目时,我想触发一个函数,该函数根据输入填充表单的其余部分。我不希望当用户手动键入值时触发此功能。我不确定如何将事件专门绑定到从下拉列表中选择项目的用户。
这里有一个小提琴:http://jsfiddle.net/AhDHk/
.HTML:
<input type="text" name="realtor-name" id="lp-realtor-name" value="" class="text ui-widget-content ui-corner-all" />
.JS:
// adds the dropdown, dropArray is the list of items for the dropdown, id is the ID of the html input.
function textDropdown(dropArray, id) {
var $input = $(id).autocomplete({
source: dropArray, // this is an array fetched with AJAX of all the items for the dropdown
minLength: 0
}).addClass("ui-widget ui-widget-content ui-corner-left");
$("<button type='button'> </button>")
.attr("tabIndex", -1)
.attr("title", "Show All Items")
.insertAfter($input)
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass("ui-corner-all")
.addClass("ui-corner-right ui-button-icon lp-drop-button")
.click(function() {
// close if already visible
if ($input.autocomplete("widget").is(":visible")) {
$input.autocomplete( "close" );
return;
}
$(this).blur();
$input.autocomplete("search", "" );
$input.focus();
});
$("form").submit(function(e) {
event.preventDefault ? event.preventDefault() : event.returnValue = false;
alert($(this).serialize());
});
}
以下是处理它的方法:
var $input = $(id).autocomplete({
source: dropArray, // this is an array fetched with AJAX of all the items for the dropdown
minLength: 0,
select: function(event, ui) { alert('test');}
}).addClass("ui-widget ui-widget-content ui-corner-left");
可能重复的: jQuery UI 自动完成选择
选择事件,在这里。
function textDropdown(dropArray, id) {
var $input = $(id).autocomplete({
source: dropArray, // this is an array fetched with AJAX of all the items for the dropdown
minLength: 0,
select:function(a,b){
alert(b.item.value + 'selected');
}
}).addClass("ui-widget ui-widget-content ui-corner-left");
相关文章:
- 在D3中组合多个事件
- AngularJS-如何只对多个事件的组合采取行动
- 某些组合键会阻止 JavaScript 中的键事件
- 如何将两个事件的变量组合为一,作为两者的总和.jquery
- 组合类和事件监听器:`this`关键字
- 组合多个事件
- Onchange组合框事件在中不起作用
- 以编程方式模糊 EXTJS 3.2.1 中的组合框控件不会触发“模糊”事件
- 如何在更改事件中获取剑道组合框的值
- 在 ExtJS 组合框选取器上滚动事件
- 为多个元素组合 jQuery 事件侦听器
- 如何创建一个侦听按键组合的事件侦听器(ctrl 和左/右箭头)
- 反应组合事件
- 清除时的 JQuery UI 组合框事件
- 有没有办法在jQuery/Javascript中组合事件
- 在 jQuery 组合框上选择下拉项后触发事件
- 焦点事件 jquery 组合框/自动完成
- react.js中的事件组合
- 在jQuery中,如何使用两个事件组合在一个对象中来指定目标元素
- 有没有一种方法可以将两个或多个执行类似操作的事件组合起来使用DRY原理