将事件处理程序挂接到jQuery自动完成组合框 [英] Hooking event handlers to jQuery Autocomplete Combobox
问题描述
我想要一些有关如何为jQuery自动完成Combox设置事件处理程序的建议: http://jqueryui.com/demos/autocomplete/#combobox .
I would like some advice on how to set event handlers for the jQuery Autocomplete Combox: http://jqueryui.com/demos/autocomplete/#combobox.
jQuery文档中的代码示例如下:
Code examples from the jQuery doc are as per below:
// Supply a callback function to handle the select event as an init option.
$( ".selector" ).autocomplete({
select: function(event, ui) { ... }
});
// Bind to the select event by type: autocompleteselect.
$( ".selector" ).bind( "autocompleteselect", function(event, ui) {
...
});
我已经尝试过-按照下面的方法-但这是行不通的.我从这份已关闭的错误报告(dev.jqueryui.com/ticket/5891)中了解到,我正在实例化组合框,然后尝试使用自动完成功能设置选项",但是我不知道如何解决它.
I have tried this - as per below - but it doesn't work. I understand from this closed bug report (dev.jqueryui.com/ticket/5891) that I am "instantiating a combobox and then trying to set options using autocomplete", but I don't understand how to fix it.
// Have: <select id="comboInput" name="comboInput"> ....
$(document).ready(function() {
$("#comboInput").combobox();
$("#comboInput").autocomplete({
select: function(event, ui) {
alert("Value selected.");
}
});
});
有人可以建议我如何进行这项工作吗?感谢您的协助!
Can anyone advise me on how to make this work? Thanks for any assistance!
推荐答案
简而言之,这就是创建带有针对"selected"事件(应为"select")的事件处理程序的组合框的条件.原型):
In short, this is what is needed to create a combobox with an event handler for the "selected" event (should be "select", but combobox is only a prototype):
<script language="javascript" type="text/javascript">
$(document).ready(function() {
// For some SELECT with ID combobox
$("#combobox").combobox({
selected: function(event, ui) {
// Event handling code goes here.
} // selected
}); // combo
}); // ready
</script>
For more detail and discussion, see my blog post: Event Handling with the jQuery Autocomplete Combobox.
这篇关于将事件处理程序挂接到jQuery自动完成组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!