Solve the compatibility problem of placeholder in IE8

Source: Internet
Author: User

Placeholder is an attribute in HTML5. You can set the placeholder attribute in the text box to display prompt text, but it is not supported by browsers with ie10 or lower, the following method enables placeholder to be used in ie10 or earlier versions.

The first method is to add the following script to the page:

<script type="text/javascript">     if( !(‘placeholder‘ in document.createElement(‘input‘)) ){       $(‘input[placeholder],textarea[placeholder]‘).each(function(){          var that = $(this),          text= that.attr(‘placeholder‘);          if(that.val()===""){            that.val(text).addClass(‘placeholder‘);          }          that.focus(function(){            if(that.val()===text){              that.val("").removeClass(‘placeholder‘);            }          })          .blur(function(){            if(that.val()===""){              that.val(text).addClass(‘placeholder‘);            }          })          .closest(‘form‘).submit(function(){            if(that.val() === text){              that.val(‘‘);            }          });        });      }   </script>

The above method does not support text boxes of the password type. Some solutions on the Internet are not perfect. Finally, we found that jquery's placeholder plug-in is not bad. The Code is as follows:

Bytes:
<script type="text/javascript">   $(function() {        $(‘input, textarea‘).placeholder();   });</script>

 

Solve the compatibility problem of placeholder in IE8

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.