简体   繁体   English

jQuery自动完成,发生更改事件

[英]jQuery autocomplete, on change event

I am trying to call a function every time an autocomplete search is changed, either by key press or by clicking one of the options of the autocomplete. 我试图每次更改自动完成搜索时都通过调用功能或单击自动完成选项之一来调用函数。 Key press works fine like this... 这样的按键效果很好...

 $('#searchScenario').on('keyup change', function () {
 //event
 }

But this won't work when I click on one of the autocomplete options. 但这在我单击自动完成选项之一时不起作用。

Here is my autocomplete initialization. 这是我的自动完成初始化。

 scenarioSearch = $('#searchScenario').autocomplete({
        source: scenarioTags,
        minLength: 0
    }).focus(function () {
        $(this).autocomplete('search', $(this).val());
    });

I have attempted other methods such as this... 我尝试了其他类似的方法...

(function () {  
var scenarioSearch = $("#searchScenario").autocomplete({ 
  change: function() {
      alert('changed');
  }
  });
  scenarioSearch .autocomplete('option','change').call(scenarioSearch );
  });

But it only triggers when the box loses focus. 但是它仅在框失去焦点时才触发。

Any help would be greatly appreciated. 任何帮助将不胜感激。

I am not at my box but can you try it using : 我不在我的盒子旁,但可以使用以下方法尝试:

select:function() {
      alert('changed');
  }

Or 要么

.select()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM