2016-04-29 98 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

這個新的答案不會增加太多以前給出的,但.. 。 –