【问题标题】:Using jquery Autocomplete with fields that have a change selector [duplicate]对具有更改选择器的字段使用 jquery Autocomplete [重复]
【发布时间】:2019-03-26 12:56:27
【问题描述】:

我有几个字段:

 <input type='text' id='field1' name='field1' class='checkMe'>
 <input type='text' id='field2' name='field2' class='checkMe'>
 <input type='text' id='field3' name='field3' class='checkMe'>

我有一个 jquery 自动完成功能:

 $('#someField').autocomplete({
       /// options
       $.ajax({
           ////
           success:function(result){
                 $.each(result,function(e,i){
                      $('#'e).val(i);
                      // -- e is a valid id of a text field

                 });
           }
       });
 });

自动完成部分工作正常。对于这些字段,我还有另一个事件监听器:

  $('.checkMe').bind('keyup change', function () {
      alert('hi');
          //do something
  });

此页面上的用户可以通过在每个字段中输入值来填写表单,或者在其他地方选择一个字段并让自动完成填写表单。

问题:当用户手动输入数据时,.checkMe 正确触发,当用户使用自动完成时,.checkMe 事件永远不会触发。

【问题讨论】:

  • 你需要自己触发,val不需要,see here

标签: jquery autocomplete


【解决方案1】:

val-doesnt-trigger-change-in-jquery中所见

解决方案是添加:

 $('#'e).val(i).trigger("change");

在我的自动完成中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2021-07-30
    • 2021-03-09
    • 2012-02-17
    • 2015-07-01
    相关资源
    最近更新 更多