IE7 上的 jquery 删除方法存在问题

Issue with jquery remove method on IE7?

本文关键字:存在 问题 方法 删除 上的 jquery IE7      更新时间:2023-09-26
<table class="myCustomers">
 <tbody>
   <tr>
     <td>
       <ul id="salesCustomers">
       <li title="cust 1"><a id="cust_1" >customer 1</a></li>
       <li title="cust 2"></li>
       </ul>
     </td>
   </tr>
 </tbody>

当我在IE 7上执行以下操作时,对应于"客户1"的DOM元素将从容器"salesCustomers"中删除,但是删除元素后,"salesCustomers"容器确实会进行调整(我的意思是IE 7显示空白空间代替它)

  $('#cust_1').remove();

它在IE8,9,火狐,铬上运行良好,但在IE 7上不起作用?

更新:-

CSS部分是

table.myCustomers li {
    margin: 8px;
}
table.myCustomers li a {
    text-decoration: none;
}
a {
    color: #000000;
    margin: 3px;
}

此代码

  $('#cust_1').remove();

只会删除标签<a id='cust1'>customer1</a>标签。它周围的<li>标签仍在DOM中。如果您的 CSS 为<li>元素分配了一些高度,它仍将显示为空白区域。

空白空间可能是因为li仍然存在。(正如Jayraj所指出的)

如果还想删除与#cust_1对应的li

你有几种方法可以做到这一点,

  1. $("[title='cust 1']").remove();
  2. $("#cust_1").parents("li").remove(); //this will remove the child element as well

测试链接