简体   繁体   中英

textarea placeholder does not work in IE10

I'm setting placeholder s of input text and they works normally in IE9+ .

<textarea style="some-style" name="some-name" id="some-id" class="some-class" 
 placeholder="awesome placeholder"></textarea>

This above does not work out. I tried also to use a plugin , but it does not change anything. Also tried to search through older questions but didn't find anything

EDIT

I noticed a strange behaviour: the content of the textarea on boot is the text of the placeholder and so not-empty, if I delete it then the textarea is empty and the placeholder works normally

You can set a text for placeholder in title attribute and use this function with jQuery library

   $('textarea').focus(function() {
        if(this.title==this.value) {
        this.value = '';
        }
    }).blur(function(){
    if(this.value=='') {
        this.value = this.title;
        }
    });

Make sure there's nothing 'inside' the textarea. No gap between the opening and closing tags. Also, I don't think the placeholder attribute works in IE9, but should in IE10.

<textarea style="some-style" name="some-name" id="some-id" class="some-class"  placeholder="awesome placeholder"></textarea>

This is what i use for IE

var eMail = $('input').val();
$('input').click(function () {
    $(this).val('');
});
$('input').focusout(function () {

    if ($('input').val() != '') {
       //..
    } else {
        $(this).val(eMail);
    }
});

You can also use it with textarea

Well I'll just go ahead and post my answer, even though this bug is old, because none of the others were suitable for me and the bug is still very much persistent.

  $('textarea').each(function() {
    // Check to see if the placeholder value equals the actual value
    if ($(this).attr('placeholder') == $(this).val()) {
      // If so, empty the actual value
      $(this).val("");
    }
  });

Basically it checks to see if any textarea element has a value that equals its placeholder, and if so it empties the value. It is a safe assumption that on page render no textarea element should have a value equalling its placeholder, so I think this is a solid fix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM