For example, display prompt text when the text box is empty
In ie10+ and Chrome browser Add placeholder properties and can be implemented, single in ie10-browser does not support this property,
The following is the implementation of placeholder in Ie10-browser
1<style type= "Text/css" >2 /*style of prompt text when the input box is empty*/3 Label.placeholder4 {5 Color:gray;6padding-left:3px;7 Cursor:text;8z-index:1000;9 Position:absolute;Ten background:transparent; Onefont-size:0. 8em; Apadding-top:4px; - } -</style> the<script type= "Text/javascript" > - /*Show/Hide hint text in input box when set input box is empty - * @param show display prompt text, default display - */ +$.fn.sethint =function(show) { - if(' Placeholder 'inchDocument.createelement (' Input ')) + return; A at varWord = This. attr ("placeholder"); - if(word) { -Show = (show = = undefined)? ( This. val () = = ""): Show;//determines whether the content is displayed depending on whether it is empty - if(Show && This. val () = = "") { - This. Prev ("Label.placeholder"). Show (); -}Else if(!show) { in This. Prev ("Label.placeholder"). Hide (); - } to } + }; - the //script for page initialization execution *$(function () { $ //IE10 and above browsers support placeholder properties and do not need to be implemented with scriptingPanax Notoginseng if(! (' Placeholder 'inchDocument.createelement (' Input '))) { -$ (": Text[placeholder],:p Assword[placeholder],textarea[placeholder]"). Wrap ("<span></span>") the. Focus (function () { +$( This). Prev ("Label.placeholder"). Hide (); A}). blur (function () { the if($( This). val () = = "") { +$( This). Prev ("Label.placeholder"). Show (); - } $}). each (function () { $ varlabelhtml = "<label class= ' placeholder ' >" + $ ( This). attr ("placeholder") + "</label>"; -$ (labelhtml). InsertBefore ( This). Click (function () { -$( This). Hide (). Next (). focus (); the}). Toggle ($ ( This). val () = = ""); - });Wuyi } the }); -</script>
Html:
<type= "text" placeholder= "Please enter user name"/>
ie10-Browser for placeholder effect