Solution for supporting placeholder attribute in IE

Source: Internet
Author: User

In HTML5, the text box, that is, input, type is text, or password, adds a property placeholder, that is, a placeholder. When the input is complete, the placeholder disappears.
This attribute is very useful, because HTML5 is required to have this attribute. However, in IE, this effect is not achieved, so we can achieve the compatibility of ie9.
I wrote a jquery plug-in to enable IE to achieve this effect.
The Code is as follows:
jQuery.fn.placeholder = function(){
var i = document.createElement(‘input‘),
placeholdersupport = ‘placeholder‘ in i;
var inputs = jQuery(this);
var input = jQuery(this),
text = input.attr(‘placeholder‘),
pdl = 0,
height = input.outerHeight(),
width = input.outerWidth(),
placeholder = jQuery(‘<span class="phTips">‘+text+‘</span>‘);
pdl = input.css(‘padding-left‘).match(/\d*/i)[0] * 1;
pdl = 5;
placeholder.css({‘margin-left‘: -(width-pdl),‘height‘:height,‘line-height‘:height+"px",‘position‘:‘absolute‘, ‘color‘: "#6C7C88", ‘font-size‘ : "12px"});{
if(input.val() != ""){
if(jQuery(this).val() != ""){
return this;


Introduce the jquery library and then introduce this plug-in. The call is as follows:

$(function (){






‘margin-left‘: -(width-pdl),




‘color‘: "#cecfc9",

‘font-size‘ : "12px"});




From Weizhi note (wiz)

Solution for supporting placeholder attribute in IE

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: 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.