1. CSS “float” 属性:
IE 语法:
document.getElementById("header").style.styleFloat = "left";
Firefox 语法:
document.getElementById("header").style.cssFloat = "left";
2. 元素的计算样式:
IE 语法:
var myObject = document.getElementById("header");var myStyle = myObject.currentStyle.backgroundColor;
Firefox 语法:
var myObject = document.getElementById("header");var myComputedStyle = document.defaultView.getComputedStyle(myObject, null);var myStyle = myComputedStyle.backgroundColor;
3. 获取元素的”class”属性:
IE 语法:
var myObject = document.getElementById("header");var myAttribute = myObject.getAttribute("className");
Firefox 语法:
var myObject = document.getElementById("header");var myAttribute = myObject.getAttribute("class");
4. 获取 label 标签的 “for” 属性:
IE 语法:
var myObject = document.getElementById("myLabel");var myAttribute = myObject.getAttribute("htmlFor");
Firefox 语法:
var myObject = document.getElementById("myLabel"); var myAttribute = myObject.getAttribute("for");
5. 获取光标位置:
IE 语法:
var myCursorPosition = [0, 0];myCursorPosition[0] = event.clientX;myCursorPosition[1] = event.clientY;
Firefox 语法:
var myCursorPosition = [0, 0];myCursorPosition[0] = event.pageX;myCursorPosition[1] = event.pageY;
6. 获取视窗或浏览器窗口的尺寸:
IE 语法:
var myBrowserSize = [0, 0];myBrowserSize[0] = document.documentElement.clientWidth;myBrowserSize[1] = document.documentElement.clientHeight;
Firefox 语法:
var myBrowserSize = [0, 0];myBrowserSize[0] = window.innerWidth;myBrowserSize[1] = window.innerHeight;
7. Alpha 透明:
IE 语法:
#myElement { filter: alpha(opacity=50);}
Firefox 语法:
#myElement { opacity: 0.5;}
IE 语法:
var myObject = document.getElementById("myElement");myObject.style.filter = "alpha(opacity=80)";
Firefox 语法:
var myObject = document.getElementById("myElement");myObject.style.opacity = "0.5";