1.萬惡的低版本IE瀏覽器只支持innerText並不支持textContent
所以我們要兼容谷歌或者火狐 ;textContent是標準方法;標準瀏覽器都支持;
function getText(
!tag,innerText ? tag.textContent : tag.innerText;
}
2. 我們在js中用 元素.style.屬性 , 只能獲取行內樣式;
我們要獲取內嵌和外鏈css樣式要用到這樣一個方法:getComputedStyle();
但是IE9以下它不支持;IE自己搞了個 對象.currentStyle 屬性,所以還是要做兼容;
function getStyle(obj, attr ){
return obj.currentStyle ? obj.currentStyle[ attr ] : getComputedStyle(obj)[attr];
//這裏注意:判斷的話,只能把currentStyle放在前面;因爲currentStyle是屬性,沒有是undefined
//而getComputedStyle是方法,沒有會報錯,所以不能放在前面判斷;
}
3. childNodes 和children;
childNodes,在標準瀏覽器下會包含文本節點;而在IE9以下只會包含元素節點;
不過我們一般用children, 幾乎不用childnode;
children在iE低版本瀏覽器和標準瀏覽器都只包含元素節點;
4. firstChild 和 firstElementChild
lastChild和lastElementChild
都會有兼容性問題
不過我們可以用children[0]和 children[children.length-1]來代替上面;