当我在chrome中使用remove()时,它可以工作,但IE无法工作

时间:2015-03-24 14:11:43

标签: jquery

运行我的mvc应用程序时,它正在使用chrome但不能在IE上运行 错误显示在下面

"JavaScript runtime error: Object doesn't support property or method 'remove()'"

1 个答案:

答案 0 :(得分:0)

由于.remove()不适合您,您可以使用Node.removeChild()直接查看Javascript以完成工作。

var elem = document.getElementById("myDiv");
elem.parentNode.removeChild(elem);

elem是您要删除的元素

根据您的评论尝试:

function removeRows() {
  $('#AssociateProfilesGrid').find('table > tbody > tr').each(function() {
      this.remove();
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="AssociateProfilesGrid">
  <table>
    <thead>
      <tr><td>This row will not be removed</td></tr>
    </thead>
    <tbody>
      <tr><td>This row will be removed</td></tr>
    </tbody>
  </table>
</div>

<button onclick="removeRows()">Remove()</button>