2009-10-07 108 views
2

我想要一個自動完成/ autoformat「To」字段在我的網站上運行,就像GMail中的一樣。jQuery電子郵件地址輸入

有沒有人知道這種事情的jQuery?

Plain JavaScript?還是有其他的選擇?

+0

我不得不從你的帖子中刪除圖片,因爲ImageShack已經刪除它並用廣告代替它。有關更多信息,請參閱http://meta.stackexchange.com/q/263771/215468。如果可能的話,你可以重新上傳它們。謝謝! – Undo

回答

1

有很多很多的jQuery位這樣做,你可以谷歌的「jquery自動完成」,看看你最喜歡哪一個。

這裏有一個是比較有名:http://docs.jquery.com/Plugins/AutoComplete

<script> 
    var emails = [ 
     { name: "Kitty Sanchez", to: "[email protected]" }, 
     { name: "Lucille Austero", to: "[email protected]" }, 
     { name: "Bob Loblaw", to: "[email protected]" }, 
     { name: "Sally Sitwell", to: "[email protected]" } 
    ]; 

    $(document).ready(function(){ 
     $("#Recipients").autocomplete(emails, { 
      multiple: true, 
      minChars: 1, 
      matchContains: "word", 
      autoFill: false, 
      formatItem: function(row, i, max) { 
       return "\"" + row.name + "\" &lt;" + row.to + "&gt;"; 
      }, 
      formatMatch: function(row) { 
       return row.name + " " + row.to; 
      }, 
      formatResult: function(row, i, max) { 
       return "\"" + row.name + "\" <" + row.to + ">"; 
      } 
     }); 
    }); 
</script> 
2

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

看看這個插件。它看起來相當健壯穩定,可能會滿足您的需求。 jQuery是您尋求的效果的完美選擇。請記住,根據你想從中獲取數據的位置,你需要創建一些ajax/php後端。

+1

我想刪除php部分,因爲任何服務器端web技術/框架都可以使用 –

1

這些答案都很好,但我認爲他正在尋找一些具體的事情電子郵件。 Gmail的電子郵件自動完成功能非常強大並且非常智能,可以考慮您最常收發電子郵件的人和其他因素。

+0

您可以在後端設計一些原始內容,假設有發送電子郵件的審覈,並且您知道是誰發送了電子郵件,他們發送給誰。 –

相關問題