<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Placeholder on 冯威的博客</title><link>https://fwhyy.com/tags/placeholder/</link><description>Recent content in Placeholder on 冯威的博客</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Wed, 12 Feb 2014 00:00:00 +0800</lastBuildDate><atom:link href="https://fwhyy.com/tags/placeholder/atom.xml" rel="self" type="application/rss+xml"/><item><title>placeholder在IE8中兼容性问题解决</title><link>https://fwhyy.com/2014/02/placeholder-in-ie8/</link><pubDate>Wed, 12 Feb 2014 00:00:00 +0800</pubDate><guid>https://fwhyy.com/2014/02/placeholder-in-ie8/</guid><description>&lt;p&gt;placeholder是HTML5中的一个属性，可以在文本框中设置placeholder属性来显示一些提示性的文字，但对IE10以下的浏览器不支持，下面方法可以让placeholder能够使用在IE10以下的版本中。第一种方法是在页面中添加下面一段脚本：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;lt;script type=&amp;#34;text/javascript&amp;#34;&amp;gt; 
 if( !(&amp;#39;placeholder&amp;#39; in document.createElement(&amp;#39;input&amp;#39;)) ){ 

 $(&amp;#39;input[placeholder],textarea[placeholder]&amp;#39;).each(function(){ 
 var that = $(this), 
 text= that.attr(&amp;#39;placeholder&amp;#39;); 
 if(that.val()===&amp;#34;&amp;#34;){ 
 that.val(text).addClass(&amp;#39;placeholder&amp;#39;); 
 } 
 that.focus(function(){ 
 if(that.val()===text){ 
 that.val(&amp;#34;&amp;#34;).removeClass(&amp;#39;placeholder&amp;#39;); 
 } 
 }) 
 .blur(function(){ 
 if(that.val()===&amp;#34;&amp;#34;){ 
 that.val(text).addClass(&amp;#39;placeholder&amp;#39;); 
 } 
 }) 
 .closest(&amp;#39;form&amp;#39;).submit(function(){ 
 if(that.val() === text){ 
 that.val(&amp;#39;&amp;#39;); 
 } 
 }); 
 }); 
 } 
&amp;lt;/script&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;上面的方法不能支持password类型的文本框，网上找了些解决方法都不是很完美，最后发现jQuery的placeholder插件还不错，代码如下：&lt;/p&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/oec2003/8946120"&gt;https://gist.github.com/oec2003/8946120&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;将placeholder.js文件引用到页面，页面中添加下面脚本：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;lt;script type=&amp;#34;text/javascript&amp;#34;&amp;gt;
$(function() {
 $(&amp;#39;input, textarea&amp;#39;).placeholder();
});
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description></item></channel></rss>