2009年5月7日 星期四

javascript讀取CSS樣式

在javascript中用object.style只能讀到HTML element的行內樣式
要讀取一個HTML element所有的css樣式

在IE中可以用object.currentStyle 這是read-only的

在firefox中可以用window.getcomputedstyle(element, pseudoElt)

用簡單的判斷式就可以跨瀏覽器:
if (object.currentStyle)
do something
else if (window.getcomputedstyle)
do something

沒有留言:

張貼留言