7处ff与ie中读写html、css相关属性的不同之处
1. float样式属性
IE syntax:
document.getElementById("test").style.styleFloat = "left";
FF syntax:
document.getElementById("test").style.cssFloat = "left";
2.获取计算之后的元素样式
IE syntax:
var element = document.getElementById("test"), elementStyle = element.currentStyle.backgroundColor;
FF syntax:
var element = document.getElementById("test"), computedStyle = document.defaultView.getComputedStyle(element, null), elementStyle = computedStyle.backgroundColor;
3.获得元素的"class"属性
IE syntax:
var element = document.getElementById("test"), classAttr = element.className; //or classAttr = element.getAttribute("className");
FF syntax:
var element = document.getElementById("test"), classAttr = element.getAttribute("class");
4.获取元素的“for”属性
IE syntax:
var element = document.getElementById("test"), forAttr = element.getAttribute("htmlFor");
FF syntax:
var element = document.getElementById("test"), forAttr = element.getAttribute("for");
5.获得鼠标的坐标位置
IE syntax:
var positionX = event.clientX, positionY = event.clientY;
FF syntax:
var positionX = event.pageX, positionY = event.pageY;
6.获取viewport,浏览器可用区域大小
IE syntax:
var browserViewportWidth = document.documentElement.clientWidth, browserViewportHeight = document.documentElement.clientHeight;
FF syntax:
var browserViewportWidth = window.innerWidth, browserViewportHeight = window.innerHeight;
7.alpha 透明度
IE syntax:
#test{ filter: alpha(opacity=50); }
var element = document.getElementById("test"); element.style.filter = "alpha(opacity=80)";
FF syntax:
#test{ opacity: 0.5 }
var element = document.getElementById("test"); element.style.opacity = "0.8";
参考:http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie/