HTML5 的placeholder属性(兼容各版本)
2014-07-01 09:24
597 查看
Placeholder是HTML5新增的另一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点时,提示文字消失。
placeholder 点击可下载(写好的案例)
其它情况:
当在IE10以下版本中占位文本的颜色是黑色;IE10以上版本(其它浏览器最新版本)为灰色,为了兼容IE10以下版本(老版本)统一让占位符更改为灰色,建议可以利用以下方法更改占位文本颜色值。
基本代码:
<input type="text" value="placeholder text" onfocus="this.style.color='#000';
this.value='';" style="color: #f00;"/>
完善代码:
<input type="text" value="placeholder text" onfocus="if(!this.haswriting){this.style.color='#000'; this.value='';}" onblur="if(!this.value){this.style.color='#f00'; this.value='placeholder text'; this.haswriting=false;}else{this.haswriting=true};" style="color:
#f00;"/>
placeholder 点击可下载(写好的案例)
其它情况:
当在IE10以下版本中占位文本的颜色是黑色;IE10以上版本(其它浏览器最新版本)为灰色,为了兼容IE10以下版本(老版本)统一让占位符更改为灰色,建议可以利用以下方法更改占位文本颜色值。
基本代码:
<input type="text" value="placeholder text" onfocus="this.style.color='#000';
this.value='';" style="color: #f00;"/>
完善代码:
<input type="text" value="placeholder text" onfocus="if(!this.haswriting){this.style.color='#000'; this.value='';}" onblur="if(!this.value){this.style.color='#f00'; this.value='placeholder text'; this.haswriting=false;}else{this.haswriting=true};" style="color:
#f00;"/>
相关文章推荐
- Html5的placeholder属性(IE兼容)实现代码
- 兼容HTML5placeholder属性
- (转)html5 Placeholder属性兼容IE6、7方法
- [干货]兼容HTML5的Placeholder属性-更新版v0.10102013
- Html5的placeholder属性(IE兼容)
- 解决html5新标签 placeholder 低版本浏览器下不兼容问题
- 【工作笔记五】html5的placeholder属性(IE如何兼容placeholder属性)
- html5的placeholder属性(IE如何兼容placeholder属性)
- html5 placeholder ie版本兼容
- Html5的placeholder属性(IE兼容)
- HTML5表单提示placeholder属性兼容IE
- 关于HTML5 Placeholder新标签低版本浏览器下不兼容的问题分析及解决办法
- IE兼容html5的placeholder属性(IE如何兼容placeholder属性)
- html5 Placeholder属性兼容IE6、7方法
- 兼容ie10以下版本的placeholder属性
- 解决html5新标签【placeholder】低版本浏览器下不兼容问题
- ie兼容html5中placeholder属性
- html5属性placeholder的js 向下兼容支持(jquery版)
- Html5的placeholder属性(IE兼容)实现代码
- html5新标签【placeholder】解决浏览器低版本不兼容问题