好像 IE8 忽略了我的点击事件!当我按下“+”按钮并在“-”上删除它时,它应该添加一个新行。我是 WEB 开发的新手,但我看不到任何其他问题。我对其进行了测试,它适用于 IE10、IE9,但不适用于 IE8!你能帮我解决这个问题吗!
我的 HTML 代码:
<table id="sysAffectedTable2">
<thead>
<tr>
<th>#</th>
<th><span class="locationName">Location Name</span></th>
<th>Subnet (Optional)</th>
<th>Add</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input type="text" id="locationName1" value="" name="locationName1"/></td>
<td><input type="text" id="subnet1" value="" name="subnet1"/></td>
<td><input type="button" style="width: 40px" id="addDiskButton2" value=" + " onclick="insertRow2()"/></td>
<td><input type="button" style="width: 40px" id="delDiskButton2" value=" - " onclick="deleteRow2(this)"/></td>
</tr>
</tbody>
</table>
我的 JavaScript 代码:
<script type="text/javascript" language="javascript">
var maxRow2=1;
var table2 = document.getElementById('sysAffectedTable2'), tbody2 = table2
.getElementsByTagName('tbody')[0], clone2 = tbody2.rows[0]
.cloneNode(true);
function deleteRow2(el) {
var i = el.parentNode.parentNode.rowIndex;
if (i != 1) {
table2.deleteRow(i);
while (table2.rows[i]) {
updateRow2(table2.rows[i], i, false);
i++;
}
maxRow2--;
} else if (i == 1) {
table2.deleteRow(i + 1);
while (table2.rows[i + 1]) {
updateRow2(table2.rows[i + 1], i + 1, false);
i++;
}
maxRow2--;
}
}
function insertRow2() {
if (maxRow2 < 32) {
var new_row = updateRow2(clone2.cloneNode(true),
++tbody2.rows.length, true);
tbody2.appendChild(new_row);
maxRow2++;
}
}
function updateRow2(row2, a2, reset2) {
row2.cells[0].innerHTML = a2;
var inp1 = row2.cells[1].getElementsByTagName('input')[0];
var inp2 = row2.cells[2].getElementsByTagName('input')[0];
inp1.name = 'locationName' + a2;
inp1.id = 'locationName' + a2;
inp2.name = 'subnet' + a2;
inp2.id = 'subnet' + a2;
if (reset2) {
inp1.value = inp2.value = '';
}
return row2;
}
</script>
你可以在这里看到它- http://jsfiddle.net/yHANj/1/
请你帮帮我!
提前致谢!