0
<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、firefox、chrome 上运行良好,但在 IE 7 上不行?

更新:-

CSS部分是

table.myCustomers li {
    margin: 8px;
}

table.myCustomers li a {
    text-decoration: none;
}

a {
    color: #000000;
    margin: 3px;
}
4

2 回答 2

2

这段代码

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

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

于 2013-09-17T04:14:26.283 回答
0

The empty space may be since the li is still there. (as pointed out by Jayraj)

If you want to remove the li corresponding to the #cust_1 as well,

You have a couple of ways to do it,

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

Test link

于 2013-09-17T04:23:18.497 回答