I see this all over the web, but was wondering if anyone has the JavaScript code for the EASIEST way to show input value on blur, but hide in on focus.
相关问题
- Is there a limit to how many levels you can nest i
- Laravel Option Select - Default Issue
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
Since this still comes up on google, I'd like to point out that with HTML 5 you can use the placeholder attribute with an input to achieve this in one piece of html.
Placeholder is now standard across modern browsers, so this really would be the preferred method.
For all browsers:
For newest version of browsers:
This always worked for me:
If you don’t care about valid HTML, you use the
placeholder
attribute. It will work out of the box on a Safari, and you can add some unobtrusive JS to mimic this behavior in other browsers.More reading:
And google. ;-)
The solution is similar to the one Josh Stodola posted, but it’s more flexible and universal.
This is what I use on my blog. Just go there and check out the source code behind.
Your input field should look something like this:
I prefer jQuery way:
It is modified Hide Form Input Values On Focus With jQuery by Zack Perdue.