ie10-Browser for placeholder effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.