如何处理自动完成组合框上的选择事件 [英] How to handle select event on autocomplete combobox

查看:67
本文介绍了如何处理自动完成组合框上的选择事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery ui自动完成组合框,我想为其处理select事件.我在Stack Overflow上找到了这个答案:将事件处理程序连接到jQuery Autocomplete Combobox

I have a jquery ui autocomplete combobox for which I want to handle the select event. I found this answer on Stack Overflow: Hooking event handlers to jQuery Autocomplete Combobox

但是这种解决方案似乎对我不起作用.我已经将以下内容添加到了组合框的原始代码中,但是当我更改选择内容时,控制台上什么都没有显示:

But this solution does not seem to work for me. I have added the below to the original code for combobox but nothing is displayed on the console when I change selection:

$( "#combobox" ).combobox({
         selected: function(event, ui) {
           console.log("Selected");
            // Event handling code goes here.
         } // selected
      });

jsFiddle

处理组合框选择事件的最佳方法是什么?

What is the best way I to handle the combobox select event?

推荐答案

在检查组合框代码时,您会看到触发了选择"事件而不是选定"事件.我不知道这个名称"selected"来自上面引用的帖子中.我正在使用JQuery UI 1.12.因此代码应如下所示:

On examining the combobox code you can see there's a trigger of a "select" event and not a "selected" event. I have no idea where this name "selected" came from in the above referenced post. I am using JQuery UI 1.12. So code should have been as follows:

$( "#combobox" ).combobox({
         select: function(event, ui) {
           console.log("Selected");
            // Event handling code goes here.
         } // selected
      });

更新了jsFiddle

这篇关于如何处理自动完成组合框上的选择事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆