7處ff與ie中讀寫html、css相關屬性的不一樣之處

1. float樣式屬性javascript

IE syntax:css

document.getElementById("test").style.styleFloat = "left";

FF syntax:html

document.getElementById("test").style.cssFloat = "left";

2.獲取計算以後的元素樣式java

IE syntax:web

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"屬性firefox

IE syntax:htm

var element = document.getElementById("test"),
  classAttr = element.className;
 //or
  classAttr = element.getAttribute("className");

FF syntax:blog

var element = document.getElementById("test"),
  classAttr = element.getAttribute("class");

4.獲取元素的「for」屬性ip

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/

相關文章
相關標籤/搜索