Case: whole search box, need default placeholder for "Please enter keyword", get focus, placeholder disappears or unavailable (does not affect normal input), after losing focus, if the user has no content input, placeholder continues to appear, continue to occupy. This code I think the front end has been very easy to write it, now HTML5 original has this "placeholder" attribute, the effect is the same as the above case description (each supported browser may not be consistent within the performance, but the role is consistent), So how does this attribute gracefully downgrade to support all modern browsers? The answer or script is JavaScript.
A legend for the above case:
Let's use Jquery's Enplaceholder plugin to achieve this effect.
Effect Demo Interface http://www.ifrans.cn/demo/enplaceholder.html
Usage:
First introduce jquery and this plugin in head
<script type=
"text/javascript"
src=
"jquery-1.7.2.min.js"
></script>
<script type=
"text/javascript"
src=
"jquery.enplaceholder.js"
></script>
Then you can call the bird.
//通过value模拟placeholder
$(
‘input‘
).placeholder();
//通过插入span元素模拟placeholder
$(
‘input‘
).placeholder({isUseSpan:
true
});