我在女巫中動態創建輸入,我需要添加一個twitter typeahead。將Typeahead動態添加到動態生成的輸入
由於html是動態生成服務器端,輸入標記只能從它的類中選擇,我發現附加它的唯一方法是使用delegate()
Jquery函數。
爲了在每個輸入中只附加一個typeahead,我在delegate()
之後使用了undelegate()
函數。
$(document).delegate(".receivers-input", "click", function() {
console.log($(this)); // input.receivers-input.col-md-4.col-sm-4.col-xs-4
$(this).undelegate($(this));
$(this).typeahead({
minLength: 0,
}, {
source: function (query, cb) {
var Request = $.ajax({
...
這種運作良好,但是當我點擊連接預輸入我有這樣的錯誤消息:
Uncaught TypeError: Cannot read property 'origType' of undefined
這可能是因爲$(this).undelegate($(this));
有誰知道如何防止錯誤或有另一種方式比delegate/undelegate
達到我的目標?
嘿,我面臨着同樣的問題,你能幫助我....你能幫我嗎?這是我的問題的鏈接..http://stackoverflow.com/questions/39181817/to-delegate-typeahead-on-dynamically-generated-input –