以下是 我在開發中遇到的情況:
1、動態刪除table里的某一行。
table:表示table對象。
k:表示行號
table.rows[k].removeNode(true); //firefox執行失敗,ie執行成功
IE與FireFox兼容寫法
table.deleteRow(k);
2、為HTML標簽自定義屬性。
inputElement:表示表單元素。
propertyName:表示表單元素下的某個屬性
inputElement.propertyName; //firefox執行失敗,ie執行成功
IE與FireFox兼容寫法
document.getElementById("txtInput").attributes["idvalue"].nodeValue
3、在指定位置插入HTML元素。
inputElement:表示表單元素。
vDiv:表示將要插入的HTML元素。
inputElement.insertAdjacentElement("AfterEnd",vDiv);//firefox執行失敗,ie執行成功
IE與FireFox兼容寫法
在firefox中,沒有該方法的定義,因此,如果需要調用該方法,需要自己重定義該方法。
在IE里執行for循環語句時原本使用break可以跳出當次循環。但在FF里面就變成了退出整個循環。這時候改用continue語句即可。
5、firefox報String contains an invalid character。
var chkBox=document.createElement('<input type="Checkbox" name="treeBox" value= '+key+'>'); //在IE下成功執行
IE與FireFox兼容寫法
firefox不支持這種createElement的定義方式,需要分步進行:
chkBox.value = key;
IE與FireFox兼容寫法
var today = new date();
var year = today.getYear();
在 Firefox 里面 getYear 返回的是 "當前年份-1900" 的值 IE里面則:
當today的年份小于2000的時候,和firefox一樣。所以最好用 getFullYear getUTCFullYear 去調用
IE與FireFox兼容寫法
新聞熱點
疑難解答