如果您在 chrome 中渲染下面的代码,您会看到这很好,但如果您使用 IE,则不会添加行。你能告诉我我在这里做错了什么,它不能在 IE 中工作吗?当我在 IE 中添加新行时,我的新行没有添加控件。这在 chrome 和 firefox 中可以正常工作,但在 IE 中不行。除非我遗漏了 IE 特有的内容,否则我在代码中找不到任何错误。感谢您的帮助。
<head>
<title></title>
<script type="text/javascript">
function insertAdditional() {
var type = document.getElementById('additional_type').value;
var node = document.createElement('li');
node.innerHTML = document.getElementById(type + 'Form').innerHTML;
document.getElementById('additional').appendChild(node);
}
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "date";
element2.size = "12";
element2.maxlength = "10";
element2.placeholder = "YYYY-MM-DD";
element2.name = "entrydate[]";
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "date";
element3.size = "12";
element3.maxlength = "10";
element3.placeholder = "YYYY-MM-DD";
element3.name = "eventdate[]";
cell3.appendChild(element3);
var cell4 = row.insertCell(3);
var element4 = document.createElement("textarea");
element4.type = "text";
element4.name = "comment[]";
element4.rows = "4";
element4.cols = "60";
cell4.appendChild(element4);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}
</script>
</head>
<body>
<h1>
Comments</h1>
<div>
<input type="button" value="Add Comment" onclick="addRow('dataTable')" />
<input type="button" value="Delete Comment" onclick="deleteRow('dataTable')" /> </div>
<table id="dataTable" width="1024px" border="1" cellpadding="10">
<tr>
<th>
<center>
Choose</center>
</th>
<th>
<center>
Entry Date</center>
</th>
<th>
<center>
Event Date</center>
</th>
<th>
<center>
Comment</center>
</th>
</tr>
<tbody>
<tr>
<td>
<input type="checkbox" name="chk[]" />
</td>
<td>
<input type="date" placeholder="YYYY-MM-DD" size="12" maxlength="10" name="entrydate[]" />
</td>
<td>
<input type="date" placeholder="YYYY-MM-DD" size="12" maxlength="10" name="eventdate[]" />
</td>
<td>
<textarea rows="4" cols="60" maxlength="500" name="comment[]"></textarea>
</td>
</tr>
</tbody>
</table>
</body>