2011-02-10 36 views
2

可能重複:
How do you disable browser Autocomplete on web form field/input tag?如何關閉「瀏覽器建議」通過Javascript?

你好,

我有我的網站的搜索引擎,顯示通過Ajax可能的結果的函數。我如何告訴瀏覽器它不應該在文本字段中顯示我之前搜索過的內容。所以當我有一個文本字段並且有人在輸入文本字段時,不應該有這樣的事情,通常會彈出並顯示搜索結果,這些都是以前製作的。例如,在Google的搜索字段中輸入時,瀏覽器不會爲我可能搜索的內容提供建議。因爲如果這個「建議領域」出現了,用戶就再也看不到我網站的Ajax建議了。

感謝您的幫助!

+0

相關http://stackoverflow.com/questions/783573/preventing-browser-text-input-suggestions – JCOC611 2011-02-10 02:06:22

回答

4

那麼,谷歌的源代碼有 「<input autocomplete=off >」:

<input autocomplete="off" class=lst type=text name=q 
maxlength=2048 value="" title="Search"> 
+0

謝謝!我沒有看到谷歌的源代碼。似乎用JavaScript加密... – phpheini 2011-02-18 15:26:03

1
document.getElementById('search').setAttribute('autocomplete', 'off');