回答

1

UPDATE:

的原理是一樣的。只要改變setTimeout功能來提交您的形式代替(如下所示:http://jsfiddle.net/X8Ghc/8/

UPDATE:

你是正確的,$(this)本來是指ui-menu(顯然沒有)。新的小提琴http://jsfiddle.net/X8Ghc/7/工作得很好。

$(document).ready(function() { 
    $("#autocomplete").autocomplete({ 
     "open": function(e, ui) { 
      //using the 'open' event to capture the originally typed text 
      var self = $(this), 
       val = self.val(); 
      //saving original search term in 'data'. 
      self.data('searchTerm', val); 
     }, 
     "select": function(e, ui) { 
      var self = $(this), 
       keyPressed = e.keyCode, 
       keyWasEnter = e.keyCode === 13, 
       useSelection = true, 
       val = self.data('searchTerm'); 
      if (keyPressed) { 
       if (keyWasEnter) { 
        useSelection = false; 
        e.preventDefault(); 
        window.setTimeout(function() { 
         //since there is apparently no way to prevent this 
         //contemptible menu from closing, re-open the menu 
         //using the original search term after this handler 
         //finishes executing (using 'setTimeout' with a delay 
         //of 0 milliseconds). 
         self.val(val); 
         self.autocomplete('search', val); 
        }, 0); 
       } 
      } 
      return useSelection; 
     }, 
     "source": ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"] 
    }); 
});​ 

原文:

此作品在a fiddle

$(document).ready(function() { 
    $("#autocomplete").autocomplete({ 
     "select": function(e, ui) { 
      var keyPressed = e.keyCode, 
       keyWasEnter = e.keyCode === 13, 
       useSelection = true; 
      console.log(e); 
      if (keyPressed) { 
       if (keyWasEnter) { 
        useSelection = false; 
        $(this).open(e, ui); 
       } 
      } 
      return useSelection; 
     }, 
     "source": ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"] 
    }); 
});​ 
+0

嗯,當我剪切和粘貼你的'選擇:功能()'到我的應用程序,我發現了以下錯誤'Uncaught TypeError:Object [object Object]沒有方法'open''。什麼是'$(this)'?它應該不是指'ui-menu',而我認爲我指的是'$('#autocomplete')' –

+0

@timpeterson:抱歉... ... :)更新了答案和小提琴。 – pete

+0

感謝您的更正。對不起,我認爲我不清楚。我不想要的是回到「選擇當前重點項目」。我想要返回提交表單發佈任何在輸入框中(不是在ui菜單中選擇的)。我對ui菜單是否打開感興趣不大。我一直得到這個錯誤'Uncaught TypeError:無法讀取位於jQuery.autocomplete.js中的未定義屬性'值'。 –