var tbl = document.getElementById("aclTbl"); (通過id獲得table)
//插入一行
var rowsLen = tbl.rows.length;
var row = tbl.insertRow(rowsLen);
aa. firefox寫法:
var chkbox = document.createElement("input");
chkbox.type = "checkbox";
chkbox.name = "checkbox_index";
chkbox.value = rowsLen;
cell = row.insertCell(0);
cell.appendChild(chkbox);
row.appendChild(cell);
bb. ie寫法:
var chkbox = document.createElement("<input type='checkbox' name='checkbox_index' value='" + rowsLen + "'/>");
cell = row.insertCell(0);
cell.appendChild(chkbox);
row.appendChild(cell);
cc. 兼容寫法:
var chkbox= document.createElement("td");
chkbox.innerHTML = "<input type='checkbox' name='checkbox_index' value='" + rowsLen + "'/>";
cell = row.insertCell(0);
cell.appendChild(chkbox);
row.appendChild(cell);
2.動態修改表格本內容
tbl.rows[row_index].cells(1).innerHTML = acl_protocol; // ie支持,firefox不支持
tbl.rows[row_index].cells[1].innerHTML = acl_protocol; // ie,firefox兼容
3. ie支持直接通過id找到元素,firefox必須通過document.getElementById(idName)找到元素。
4. 當同名checkbox只有一個的時候,在firefox中document.getElementById(checkbox_name).length=undifined.在IE中測試時,document.getElementById(checkbox_name).length有時爲1,有時爲undifined,不知是什麼原因。
5.在IE中經常定義var $ = document.getElementById,後面就用$代替document.getElementById,如var temp = $("test");。我在firefox中使用這種方法提示錯誤,後來將var temp = $("test")改爲var temp = document.getElementById("test"),運行正常。