How can IE Be compatible with the placeholder attribute?
In front-end development, you often need to set the placeholder attribute for the input. However, placeholder is a new attribute of HTML5 and is not compatible with IE10 or earlier. How can it be perfectly compatible?
Searching on the internet is actually quite simple. You can use the following methods:
<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>
This code is easy to understand, but it is not supported by the type = password type when used, so you can continue searching until JPlaceHolder. js is available. It feels good and easy to use.
<! DOCTYPE html>
: JPlaceHolder. js