删除()在IE11中无效。请提供以下代码的任何解决方案。
var TD1= document.getElementById('firstTbl').
getElementsByTagName('tr')[0].getElementsByTagName('td')[4];
//This remove is not working in IE.
firstTD1.remove();
HTML 代码:
<table id="firstTbl">
<tr>
<td> <div class="stylediv">Basic </div> </td>
<td> <div class="stylediv">Critical </div> </td>
<td> <div class="stylediv">Surgical </div> </td>
<td> <div class="stylediv">Hospital </div> </td>
<td> <div class="stylediv">Waiver </div> </td>
</tr>
</table>
注意:目标是隐藏豁免表格行。
答案 0 :(得分:0)
参见下面的代码片段:在IE和Safari中正常工作
<html>
<table id="firstTbl">
<tr>
<td> <div class="stylediv">Basic </div> </td>
<td> <div class="stylediv">Critical </div> </td>
<td> <div class="stylediv">Surgical </div> </td>
<td> <div class="stylediv">Hospital </div> </td>
<td> <div class="stylediv">Waiver </div> </td>
</tr>
</table>
<script>
var TD1= document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[4];
//This remove is not working in IE.
console.log(TD1.parentNode);
TD1.parentNode.removeChild(document.getElementsByTagName('td')[4]);
</script>
</html>
&#13;
答案 1 :(得分:-1)
所有浏览器都不支持方法remove
:
而是删除元素,如下所示:
var TD1 = document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[4];
TD1.parentNode.removeChild(TD1);