2013-01-19 27 views

回答

5

只需使用佔位符文本

<input id="searchInput" type="text" placeholder="Search Here" /> 

http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute

+2

請_on't_鏈接到http://www.w3fools.com,請參閱http://meta.stackexchange.com/questions/120025/will-i-be-downvoted-for-giving-a-w3schools-link。這是官方資源:http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute – Zeta

+0

哦,謝謝。我沒有意識到。我將更新並刪除 – NinjaNye

+0

如果您要尋找佔位符「polyfill」以防萬一您必須使其與Microsoft Internet Explorer兼容,您可以檢查此jQuery插件https://github.com/dciccale/placeholder - 增強 –

0

如果瀏覽器提供HTML5功能,則可以簡單地使用placeholder屬性。

但是,如果用戶代理不提供HTML5功能,則可以使用onfocusonblur

0

您可以使用佔位符爲你的代碼。

<input id="searchInput" type="text" placeholder="Search Here" /> 

這裏有一個workind fiddle

0

既然你說的jQuery,jquery-watermark是一個很好的插件。

無論瀏覽器的功能如何,它都會添加水印。

它將使用placeholder瀏覽器是否支持它,並退回到在不

$('#searchInput').watermark('Search Here');