IE9 placeholder 不兼容的解决
坑爹的IE9-,真的是够够的了,不过公司不要求兼容这个玩意了,自己觉得兼容这个鬼还是挺有挑战性的,自己也碰到不少难题,一个个解决。
css:
.placeholderColor { color : #999; }
先判断浏览器类型(仅判断IE,如果需要请自行查找,线上很多):
function myBrowser(){
var userAgent = navigator.userAgent;
var isOpera = userAgent.indexOf("Opera") > -1;
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
if (isIE) {
var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 = IE10 = IE11=false;
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
IE55 = fIEVersion == 5.5;
IE6 = fIEVersion == 6.0;
IE7 = fIEVersion == 7.0;
IE8 = fIEVersion == 8.0;
IE9 = fIEVersion == 9.0;
IE10 = fIEVersion == 10.0;
IE11 = fIEVersion == 11.0;
if (IE55) {
return "IE55";
}
if (IE6) {
return "IE6";
}
if (IE7) {
return "IE7";
}
if (IE8) {
return "IE8";
}
if (IE9) {
return "IE9";
}
}
}
下面是placeholder的修复函数:
function fix_ie_placeholder(){
$("[placeholder]").each(function(){
var el = $(this);
var placeholder = el.attr("placeholder");
if(el.prop("type")=="password")
{
el.focus(function ()
{
$(this).prop("type","password");
if($(this).val() == $(this).attr("placeholder"))
{
$(this).val('').removeClass("placeholderColor");
}
}).blur(function ()
{
if($(this).val()=='')
{
$(this).prop("type","text");
$(this).val($(this).attr("placeholder")).addClass("placeholderColor");
}
}).blur();
if(el.val()==''||el.val()==el.attr("placeholder"))
{
el.rop("type","text");
el.val($(this).attr("placeholder")).addClass("placeholderColor");
}
}
else
{
el.focus(function ()
{
if($(this).val() == $(this).attr("placeholder"))
{
$(this).val('').removeClass("placeholderColor");
}
}).blur(function ()
{
if($(this).val()=='')
{
$(this).val($(this).attr("placeholder")).addClass("placeholderColor");
}
});
if(el.val()==''||el.val()==el.attr("placeholder"))
{
el.val($(this).attr("placeholder")).addClass("placeholderColor");
}
}
});
};
如果为IE9,则执行placeholder修复函数:
if(myBrowser() == "IE9"){
fix_ie_placeholder();
}
OK,试一下吧,应该好用,我自己测试IE9没问题。Happy New Year!
IE9 placeholder 不兼容的解决的更多相关文章
- placeholder不兼容 IE10 以下版本的解决方法
对于密码输入框placeholder的兼容问题:HTML代码:<input type="password" id="loginPassword" plac ...
- 几个常用的CSS3样式代码以及不兼容的解决办法
原文:几个常用的CSS3样式代码以及不兼容的解决办法 border-radius实现圆角效果 CSS3代码: -webkit-border-radius:10px; -moz-border-radiu ...
- spirng中的asm与jdk不兼容<已解决>
转载自:spirng中的asm与jdk不兼容<已解决> 前言 不知道前面对eclipse做了什么,使用maven来创建项目,然后转成web,启动的时候一直报错.我弄了好久,还是无法解决,先 ...
- VMware workstation虚拟机配置文件不兼容无法使用解决方法
VMware workstation虚拟机配置文件不兼容无法使用解决方法打开VMware workstation虚拟机提示:配置文件"--.vmx"是由Vmware产品创建,但该产 ...
- js解决IE8、9下placeholder的兼容问题
由于placeholder是html5的新属性,在IE8.IE9下是不能显示的,有兼容性问题. 解决思路: 1.判断目前浏览器是否支持placeholder属性 2.若不支持,则将type=" ...
- input事件在ie9以下不兼容问题完美解决
上周四好不容易加了几天班把刚接手的一个pc页面做完,周五同事说要兼容ie7~ie9,结果在上面一跑,输入都没法输入. 我的需求是用6个span作为虚拟的密码输入框,实际上是用一个藏在页面里的input ...
- ie9 placeholder兼容
.phcolor{ color:#999;}//css样式 function isPlaceholer(){ var input = document.createElement("inpu ...
- 解决IE中placeholder的兼容问题
定义和用法 placeholder 属性提供可描述输入字段预期值的提示信息(hint). 该提示会在输入字段为空时显示,并会在字段获得焦点时消失. 注释:placeholder 属性适用于以下的 &l ...
- ie9 placeholder兼容代码方法
function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r ...
随机推荐
- C# 函数3
//获取部分 public class GF_GET { /// <summary> /// 根据坐标点获取屏幕图像 /// ...
- 对称加密&非对称加密
对称密钥密码算法的特点: 算法简单,加/解密速度快,但密钥管理复杂,不便于数字签名: 非对称密钥密码算法的特点: 算法复杂,加/解密速度慢,密钥管理简单,可用于数字签名. 所以将两者结合起来,形成混合 ...
- 0608pm单例模式and面向对象的六大原则
//把类控制住,不让外界造她的对象class DA{ public $name; static private $dx;//存放对象的变量 //将构造变为私有,外界没法造对象 private func ...
- 流量分析系统---flume(测试flume+kafka)
1.在flume官方网站下载最新的flume wget http://124.205.69.169/files/A1540000011ED5DB/mirror.bit.edu.cn/apach ...
- grep命令详细解析 --非原创 原作者ggjucheng
简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...
- flex datagrid 导出csv
public function exportToCSV(dataGrid:DataGrid):void { var dataProviderCollection:ArrayCollection = d ...
- 微信小程序相关资料整理
微信小程序官方介绍https://mp.weixin.qq.com/debug/wxadoc/introduction/index.html?t=201818 微信小程序开发资源https://jue ...
- vagrant搭建
1.在官网下载对应的vagrant版本 https://www.vagrantup.com/downloads.html (下载最新版本) https://releases.hashicorp.com ...
- 20145240 《Java程序设计》第六周学习总结
20145240 <Java程序设计>第六周学习总结 教材学习内容总结 InputStream与OutputStream 10.1.1串流设计的概念 Java将输入/输出抽象化为串流,数据 ...
- 线性代数:Ax=b的解
n列的矩阵A,当且仅当向量b是列空间C(A)的一个向量时,Ax=b有解. C(A)的零空间是N(A),N(A)正交补是A的行空间C(T(A)), 依据上一章的结论,任何Rn向量可以表示为r+n,其中n ...