placeholder在IE下的兼容问题
最近写项目要求兼容到ie8,写完了去ie测试的时候,发现了placeholder在ie下的兼容问题,为了解决,搜罗网上各种牛人的解决方案,自己总结如下:
css样式(设置各浏览器下placeholder的样式问题):
//谷歌浏览器
input::-webkit-input-placeholder{
font-family: "Microsoft Yahei", 微软雅黑, sans-serif,"Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", STHeiti, 华文细黑,"PingFang SC";
font-size:14px;
color:#ccc;
}
//火狐4-18使用伪类
input::-moz-placeholder{
font-family: "Microsoft Yahei", 微软雅黑, sans-serif,"Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", STHeiti, 华文细黑,"PingFang SC";
font-size:14px;
color:#ccc;
}
//火狐19+使用伪元素
input:-moz-placeholder{
font-family: "Microsoft Yahei", 微软雅黑, sans-serif,"Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", STHeiti, 华文细黑,"PingFang SC";
font-size:14px;
color:#ccc;
}
//IE10使用伪类
input::-ms-input-placeholder{
font-family: "Microsoft Yahei", 微软雅黑, sans-serif,"Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", STHeiti, 华文细黑,"PingFang SC";
font-size:14px;
color:#ccc;
}
js代码(判断是否支持placeholder)
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('');
}
});
});
}
在input输入数字后,会出现黄色的背景,解决代码如下:
nput:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
input[type=text]:focus, input[type=password]:focus, textarea:focus {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
placeholder在IE下的兼容问题的更多相关文章
- input的placeholder在ie9下不兼容的结局办法。
/* IE9placeholder支持 */ if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder ...
- input 的 placeholder属性在IE8下的兼容处理
placeholder是input标签的新属性,在使用的时候有两个问题: 1.IE8 下不兼容 处理思路: 如果浏览器不识别placeholder属性,给input添加类名placeholder,模仿 ...
- html5的placeholder属性(IE如何兼容placeholder属性)
界面UI推荐 jquery html5 实现placeholder兼容password IE6 html5的placeholder属性(IE如何兼容placeholder属性) 2013-01-05 ...
- 解决360、猎豹浏览器等极速模式下css3兼容问题
有时候你会发现你写的animation动画的css3效果,在IE.谷歌.火狐等主流的新版本的浏览器的是没有什么兼容问题的,即便你不写前缀,也是可以显示动画效果的.然后,你本地在360浏览器或猎豹浏览器 ...
- 0c-42-ARC模式下如何兼容非ARC的类
1.ARC模式下如何兼容非ARC的类 让程序兼容ARC和非ARC部分.转变为非ARC -fno-objc-arc 2.将MRC转换为ARC ARC也需要考虑循环引用问题:一端用strong,一端用we ...
- input 光标在 chrome下不兼容 解决方案
input 光标在 chrome下不兼容 解决方案 height: 52px; line-height: normal; line-height:52px\9 .list li input[type= ...
- [转]FireFox与IE 下js兼容触发click事件的代码
本文转自:http://www.jb51.net/article/16549.htm FireFox与IE 下js兼容触发click事件 ,对于需要兼容这两者的朋友,就需要参考下下面的代码了<a ...
- 1.ARC模式下如何兼容非ARC的类
ARC模式下如何兼容非ARC的类 :转变为ARC的, -f-objc-arc 非ARC模式下如何兼容ARC的类 :转变为非ARC -fno-objc-arc
- ie下不支持placeholder 用jquery来完成兼容
这是我的第一个博客,还是写点正经的,希望对做前端朋友有所帮助.最近在做的项目placeholder不兼容ie,这个可以兼容IE的输入框的HTML新增的placeholder的显示下面是代码:$( do ...
随机推荐
- 前端第一篇---前端基础之HTML内容
前端基础之HTML内容 阅读目录(Content) 一.HTML初识 1.web服务本质 2.HTML是什么 3.HTML不是什么 二.HTML文档结构 三.HTML标签格式 四.HTML注释 五.H ...
- 每天一点点之 taro 框架开发 - taro静态资源引入
1.说明: taro中客园自由的引用静态资源,不需要安装任何的loader 引用样式文件 通过ES6的import引入 2.引用js文件 import { functionName } from '. ...
- Hibernate(八)--session的两种获取方式
openSession getCurrentSession Hibernate有两种方式获得session,分别是: openSession和getCurrentSession他们的区别在于1. 获取 ...
- LICEcap--一款录屏生成Gif的软件
下载地址:http://www.cockos.com/licecap/ 效果图:
- MySQL新增数据,存在就更新,不存在就添加
1.插入一条数据,存在就更新,不存在就更新(必须现有唯一键)使用insert ignore语句: insert ignore into table(col1,col2) values ('a','b' ...
- Monthly Expense(最大值最小化问题)
POJ-3273 ...
- 吴裕雄--天生自然Django框架开发笔记:Django Admin 管理工具
Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.可以在项目的 settings.py 中的 INSTALLED_APPS 看到它: ...
- Android自定义View——仿滴滴出行十大司机评选活动说明
滴滴出行原版图 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 仿图 ? ? ? ? ? ? 1.分 ...
- POJ - 3657 Haybale Guessing(二分+并查集)
题意:有N个大小各不相同的点,给定Q个询问,格式为q1,q2,A,表示区间q1~q2的最小值是A,问第一个与之前询问结果出现冲突的询问. 分析: 1.二分询问的标号mid,查询1~mid是否出现询问冲 ...
- ORACLE增删改查以及case when的基本用法
1.创建table create table test01( id int not null primary key, name ) not null, gender ) not null, age ...