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 ...
随机推荐
- VIMTUTOR 1.7中文版
文章来源:http://waterxfire.blog.hexun.com/4106986_d.html =============================================== ...
- Python2 socket 多线程并发 TCPServer Demo
#coding=utf-8 import socket import threading,getopt,sys,string opts, args = getopt.getopt(sys.argv[1 ...
- python 文件格式为 txt 转换成 csv 格式
1 txt 文件的读取 open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=Tr ...
- 通过ip得到所在城市,以及城市所在经纬度坐标(监控系统中用的该代码,小航哥)
监控系统中就是利用的该段代码,实现通过ip得到所在城市,以及城市所在经纬度坐标,最后得以利用echarts实现模拟迁移的效果 api官方介绍: http://lbsyun.baidu.com/inde ...
- Kattis - convexpolygonarea 【数学】
题意 给出一系列点,求这个多边形面积 思路 向量叉积 AC代码 #include <cstdio> #include <cstring> #include <ctype. ...
- Service Fusing
服务熔断也称服务隔离,来自于Michael Nygard 的<Release It>中的CircuitBreaker应用模式,Martin Fowler在博文CircuitBreaker中 ...
- 吐槽 MySQL数据库jdbc操作,varchar类型占位符问题——单引号造孽
很长时间不写代码动手能力明显下降很多常见的错误还是经常发生,今天吐血了一次. 简单的坑总是要多跳几次才能甘心.很清晰的记得大学的时候在此坑差点闷死,现在又跳进这个坑了,搞了半天终于知道错在哪里. St ...
- 跨平台移动开发_PhoneGap 使用Accelerometer 加速器
使用Accelerometer 加速器效果图 示例代码 <!DOCTYPE html> <html> <head> <title> Cude Phone ...
- KestrelHttpServer
source code of Kestrel of documentation https://github.com/aspnet/KestrelHttpServer https://github.c ...
- 【bzoj2151】种树(堆/优先队列+双向链表)
题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2151 这道题因为优先队列不怎么会用,而且手写堆的代码也不长,也想复习一下手写堆的写法…… ...