1

我正在动态地将行添加到 Jquery 对话框中存在的表中。每当关闭对话框时,我想清除该表的除第一行之外的所有行,这样如果再次打开对话框,则只能看到新的行集。

我的目标是在打开此对话框时带一个空表。

这是我的对话框代码

$( "#personPmt" ).dialog({
    autoOpen: false,
    width: 675,
    modal: true,
    position: { my: "left top", at: "left bottom", of: $("#pmtDetails") },
    close: function() {
      $('#personPmtTable').remove("tr:gt(0)");
     }
  });

这是我的对话

<div id="personPmt" title="Personal Payment">
      <table border="0" cellpadding="0" cellspacing="0" class="pmtEntry" id="personPmtTable">
        <tr>
          <th style="display:none">ID</th>
          <th class="cell_date">DOS</th>
          <th class="cell_code">CPT</th>
          <th class="cell_name">Description</th>
          <th class="cell_amt">Billed</th>
          <th class="cell_amt">Payment</th>
          <th class="cell_amt">Balance</th>
          <th class="cell_amt">New Balance</th>
        </tr>            
      </table>
    </div>
4

2 回答 2

2

将您的标题包装在一个thead元素中

<div id="personPmt" title="Personal Payment">
  <table class="pmtEntry" id="personPmtTable">
    <thead>
      <tr>
        <th style="display:none">ID</th>
        <th class="cell_date">DOS</th>
        <th class="cell_code">CPT</th>
        <th class="cell_name">Description</th>
        <th class="cell_amt">Billed</th>
        <th class="cell_amt">Payment</th>
        <th class="cell_amt">Balance</th>
        <th class="cell_amt">New Balance</th>
      </tr>
    </thead>
    <tbody>
    </tbody>        
  </table>
</div>

然后删除tbody其中将thead保持不变的所有内容。

$("#personPmtTable tbody tr").remove();

只需确保将新行附加到tbody. :)

于 2013-01-11T14:21:49.790 回答
1

尝试这个

 $('#personPmt >  tr').not(':first').remove();
于 2013-01-11T14:30:56.587 回答