admin 管理员组

文章数量: 1086019

So, for instance facebook's search bar has faint word that says "search", but when you click on the bar, it bees blank and you may begin typing, when you click away the "search" goes back.

Similarly, SO's ask a question title box has faint words that go away when you start typing.

I'm not too sure what this effect is called, but I'm wondering if theres a jQuery plugin that helps to achieve this. This isn't particularly difficult to program, but I thought why reinvent the wheel if someone already made a plugin for it.

So, for instance facebook's search bar has faint word that says "search", but when you click on the bar, it bees blank and you may begin typing, when you click away the "search" goes back.

Similarly, SO's ask a question title box has faint words that go away when you start typing.

I'm not too sure what this effect is called, but I'm wondering if theres a jQuery plugin that helps to achieve this. This isn't particularly difficult to program, but I thought why reinvent the wheel if someone already made a plugin for it.

Share Improve this question asked Jan 4, 2011 at 1:44 Razor StormRazor Storm 12.3k20 gold badges95 silver badges151 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

I made a jQuery plugin that does just that!

Update

I've since moved it to GitHub and rewrote it to address some issues. Enjoy! Feel free to email me where you use it, so I can feel useful :)

HTML5 has a feature called "placeholder" that achieves this. For example:

<input name="search" placeholder="Search" />

Of course, HTML5 isn't supported by all browsers, so javascript would do the trick elsewhere.

本文标签: javascriptHow do I make faint words in search bar that go away when you clicktypeStack Overflow