English 中文(简体)
在加起来后,在 j里重新设置/搬走桌旁。
原标题:After adding, resetting/removing table rows in jQuery
<table id="myTable" style="width: 650px;">
  <tbody>
    <tr style="font-weight: bold;">
        <td>Name</td>
        <td>Price</td>
        <td>Supplier</td>
        <td>Amount</td>
        <td>Basket</td>
    </tr>
  </tbody>
</table>

is my HTML.

这是我目前的“贱民共同倡议”:

    $.post( /ajax/products , { method:  search , string: searchstring, category: $( #search_category ).val() }, function(data) {
        data = $.parseJSON(data);
            $( #myTable > tbody:last ).append( <tr><td> +b.name+ </td><td> +b.price+ </td><td></td><td></td></tr> );
        });
    });

Each time you key up, the above js executes. Now when you are looking for Cookies, and you starts to write, it sends a ajax post with "C" then "Co" then "Coo" etc.

Already at the first ajax call it has found results that are starting with C. Therefore it appends to the table. Now it also found results for "Co" (same results as "C", because theres only Cookies in the db at the moment).

同科奥、库克群岛、库克群岛、库克群岛、库克群岛一样,......你们也站在了。 结果是各表的档次。

So what i wish to do is like cleaning/removing the <tr> s thats inside #myTables tbody, before it appends (actually just before the $.post()).

但是,它不应去掉第一个<代码><tr>,正如你在我前面的html中看到的那样,该编号为一栏标题。

How can i do this?

最佳回答

如果不改变你的html,你可以写:

var rows = $( #myTable ).find( tr );
rows.each(function(index, value) {
  if (index > 0) {
    $(value).remove();
  }
});
$( #myTable > tbody:last ).append( <tr><td> +b.name+ </td><td> +b.price+ </td><td></td><td></td></tr> );

不过,我的建议是使用<条码>第作为表格标题:

<table id="myTable" style="width: 650px;">
  <thead>
    <tr style="font-weight: bold;">
      <td>Name</td>
      <td>Price</td>
      <td>Supplier</td>
      <td>Amount</td>
      <td>Basket</td>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

之后,你的 j子可以:

 $( #myTable > tbody ).empty().append( <tr><td> +b.name+ </td><td> +b.price+ </td><td></td><td></td></tr> );
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签