简体   繁体   English

自动完成后更改事件

[英]Change event after autocomplete

I have a ruby on rails application with an input text field that has an autocomplete mechanism.我有一个 ruby on rails 应用程序,其输入文本字段具有自动完成机制。 This mechanism works like this这个机制是这样工作的

$(function() { if ($('#autocompleting_field').autocomplete) { function.... } });

No I want to call a controller action when this field changes不,我想在此字段更改时调用 controller 操作

jQuery(function($) { $('#autocompleting_field').change(function() { call the controller });

Now I have the problem that the controller is called right at the moment that I type in some words in the field but not after I have selected something from the autocomplete mechanism现在我遇到的问题是,在我在字段中输入一些单词的那一刻,controller 被调用,但在我从自动完成机制中选择了一些内容之后没有

You have to bind your after function with select event of autocomplete.您必须将 function 之后的select事件绑定到自动完成。 Like this:像这样:

$(function() {
  if (
    $('#autocompleting_field').autocomplete({
      select: function(event, ui){
        //the after function
      }
  }) {
    function....
  }
});

Although I'm not sure why you use the if虽然我不确定你为什么使用if

Note: assuming http://jqueryui.com/demos/autocomplete/ [Events->'select']注意:假设http://jqueryui.com/demos/autocomplete/ [Events->'select']

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

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