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