2016-06-30 47 views
-1

我有以下代碼。JQuery。自動完成焦點不起作用

function halle(row, settings, row_element) { 
    $('input', row).autocomplete({ 
     minLength: "0", 
     source: "../../shared/hallensuche.aspx", 
     select: function (e, ui) { 
      $(this).val(ui.item.label); 
      //update hallennr 
      var aPos = oTableAnwurfzeiten.fnGetPosition(row_element); 
      oTableAnwurfzeiten.fnUpdate(ui.item.value, aPos[0], 11); 
      isHalleChanged = true; 
      $(this).focus().select(); 
      return false; 
     }, 
     search: function (e, ui) { 
     }, 
     focus: function (e, ui) { 
      $(this).val(ui.item.label); 
      return false; 
     } 
    }).focus(function (e, ui) { 
     $(this).autocomplete("option", "source", "../../shared/hallensuche.aspx?focus=true"); 
     $(this).trigger('keydown.autocomplete'); 
     $(this).select(); 
     return false; 
    }).keydown(function (e, ui) { 
     $(this).autocomplete("option", "source", "../../shared/hallensuche.aspx?focus=false" + $('input', row).val()); 
    }); 
} 

如果我在輸入中寫入了某些東西,則執行keydown命令。在.focus中沒有任何反應。當我嘗試alert()時,它會起作用。自動完成未執行,因此不會發送「focus = true」。有誰知道我做錯了什麼?

對不起我的英文不好:d

+0

你是什麼意思*「focus = true」沒有發送*?我沒有看到這樣的代碼。爲什麼你有兩個不同的處理程序專注於焦點? –

回答

0

嘗試使用focusin,而不是重點。更新的代碼將如下所示:

$('input', row).autocomplete({ 
     minLength: "0", 
     source: "../../shared/hallensuche.aspx", 
     select: function (e, ui) { 

     }, 
     search: function (e, ui) { 
     }, 
     focus: function (e, ui) { 
      $(this).val(ui.item.label); 
      return false; 
     } 
    }).on("focusin",function (e, ui) { 
     console.log("trigger here"); 
    }).keydown(function (e, ui) { 

    }); 

請參閱演示here

+0

沒有變化。儘管我獲得了console.log,但是,自動完成功能無法運行。在XHR下的firefox網絡分析中沒有執行post。只有當他進入keydown – Hadda