浏览器兼容是一件很头疼的事,其中又属 ie8 现在整理一下常遇到的问题和解决方式,后期会陆续更新。。。
js 涉及的统计一下:
- IE8 兼容 console.log
window.console =
window.console ||
(function () {
var c = {
};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = function () {
};
return c;
})();
- String.trim()方法,去除空格事件不能够兼容 iE8,9
if (!String.prototype.trim) {
String.prototype.trim = function trim() {
return this.replace(/^\s+|\s+$/g, "");
};
}
-
oninput,onchange,onpropertychange
oninput事件 :当前对象属性发生改变,都会触发事件(非 ie)
onpropertychange :是 ie 版本
在 input 中,如果想捕获用户的键盘输入,用 onkeyup 检查事件就可以了,但是 onkeyup 并不支持复制和粘贴,因此需要动态监测 textarea 中值的变化,这就需要 onpropertychange(用在 IE 浏览器)和 oninput(非 IE 浏览器)结合在一起使用:Ev.on(ele, "input propertychange", function (e) { // do something });
-
placeholder
https://github.com/mathiasbynens/jquery-placeholder
IE8 下不支持 HTML5 属性 placeholder,不过为解决此问题的 js 插件挺多的,比如:jquery-placeholder。 -
在谷歌浏览器中点击事件 onclick 默认会触发 onmouseout 和 onmouseleave
if (event.relatedTarget != null) {
//doSomeThing()
}
该属性不支持 IE,但 ie 不会出现谷歌这种情况 2. Css 涉及的统计一下:
- ie 不兼容 border-radius
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
behavior: url('../lib/PIE-1.0.0/PIE.htc'); /*引用PIE.htc文件的路径*/
- text-overflow 文本溢出
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsis; /* for Opera */
text-overflow: ellipsis; /* for IE */
3.不兼容 line-height
line-height: 32px;
line-height: 32px\9; /*IE8*/
*line-height: 32px; /* IE7支持 */
_line-height: 32px; /* IE6支持 */
-ms-line-height: 32px; /*IE9+支持*/
-webkit-line-height: 32px; /*chrome safair*/
-moz-line-height: 32px; /*火狐*/
- 兼容 html5 标签和 css3 的一些属性
html5shiv.js、html5media.js、respond.js
modernizr(一款兼容 css3、html5 等元素的插件) - box-shadow
/**filter:--低于ie8的--*/
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(color=#CCCCCC,direction=0,strength=6)
progid:DXImageTransform.Microsoft.Shadow(color=#CCCCCC,direction=90,strength=6)
progid:DXImageTransform.Microsoft.Shadow(color=#CCCCCC,direction=180,strength=6)
progid:DXImageTransform.Microsoft.Shadow(color=#CCCCCC,direction=270,strength=6)";
- rgba()和 opacity:
opacity:不能实现元素透明文字不透明的效果
opacity: 0.5;
/** ie: filter:Alpha(opacity=x) */
rgba :实现元素透明文字不透明的效果
background: rgba(255, 255, 255, 0.1);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#19ffffff,endColorstr=#19ffffff);