We all know that HTML5 's input new attribute has placeholder= "", then this incompatible IE low version we can only write with the script.
First HTML creates a new input
<input type= "text" class= "input" value= "Please enter search content"/>
Then we introduce the corresponding JS library, then use jquery
1 <script src= "Js/jquery-1.8.3.min.js" ></script> 2 <script> 3 $ (". Input"). Bind ( {4 focus:function () { 5 if (this.value = = This.defaultvalue) { 6 this.value= ""; 7 } 8 }, 9 blur:function () {Ten if (this.value = = "") {one this.value = This.defaultvalue; ), </script>
Simple, so that is OK, then this is the text of input, we want to password password also can display IE low version, we use the method is to use two input, a text default display, a password default hidden, When text gets focus password display, text hidden, no input content loses focus text display, password display, OK, nonsense don't say more, look at the code!
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8" />5 <title>Password box hint</title>6 </Head>7 <Body>8 9 <inputtype= "text"value= "Login Password"class= "Show" >Ten <inputtype= "Password"class= "Log_paw"style= "Display:none;"> One A - <Scriptsrc= "Js/jquery-1.8.3.min.js"></Script> - <Script> the $('. Show'). Focus (function(){ - varText_value= $( This). Val (); - if(Text_value== This. DefaultValue) { - $( This). Hide (); + $( This). Next ('Input.log_paw'). Show (). focus (); - } + }); A $('Input.log_paw'). Blur (function() { at varText_value= $( This). Val (); - if(Text_value== "') { - $( This). Prev ('. Show'). Show (); - $( This). Hide (); - } - }); in </Script> - </Body> to </HTML>
Well, the code is here, hope to help you!
Use jquery to make input prompt content, compatible with IE8 above