2016-04-29 97 views
-1

你好,我正在使用typeahead jQuery库。在键盘上调用键头功能

我想在keyup中运行该函数,但它现在正在工作。

jQuery代码:

$.typeahead({ 
    input: '.js-typeahead-car_v1', 
    minLength: 1, 
    maxItem: 0, 
    order: "asc", 
    hint: true, 

    source: { 
     searchkey: { 
      url: { 
       type: "POST", 
       url: "/search", 
       data: { 
        myKey: "muvalue" 
       } 
      } 
     } 
    }, 
    callback: { 
     onClick: function (node, a, item, event) { 
      $("#topsearchbtn").trigger("click"); 
     }, 
    } 
}); 

HTML:

<input type="text" name="term" class="form-control input-sm js-typeahead-car_v1" 
     maxlength="64" placeholder="Search Entire store here..." id="tags" autocomplete='off' /> 

我怎么能说上KEYUP $.typeahead({})

现在它不是每次都发送第一次请求的请求。

回答

1

的预输入,意味着要绑定这样的:

$("#tags").typeahead({ 
    // Arguments 
}); 

看到一个工作示例here

在你的键入查询中某处可能有错误。

+0

谢谢,但相同的搜索建议不来了。 –

+0

这个函数被触发,我对此毫无疑问。在你的情况下,也许你在typeahead方法中传递的对象是错误的。 –

+0

@DeepParekh你可以尝试使用typeahead函数中最少量的参数来确保事情正确。 –

0
$(document).on('keyup', '#tags', function() { 
    $.typeahead({ 
     // your code 
    }); 
} 

$('#tags').on('keyup', function() { 
    $.typeahead({ 
    // your code 
    }); 
} 
+1

这个新的答案不会增加太多以前给出的,但.. 。 –