English 中文(简体)
JQuery Clone is cloning final row s data
原标题:
  • 时间:2009-12-09 07:05:21
  •  标签:
  • jquery
  • clone

I am running into a problem. I was using:

$(this).parents("tr:first").remove();

to delete the row the user clicked on and then:

var row = $( #picTableDisplay tbody>tr:last ).clone(true)
            .insertAfter( #picTableDisplay tbody>tr:last );

to replace a new (empty) row at the bottom of the table.

But, when the table is full (12 rows) and the user wants to remove a row, the bottom table (that has data) gets cloned (with the data).

In this scenario, how do I remove the clicked on row and add a row to the bottom of the table that is empty?

Thanks.

最佳回答

It seems to be doing exactly what you ve told it to do... cloning the last row, with or without data.
The solution is simple - don t do it.

  1. Clone a last invisible row (so you have 13 rows), or
  2. Clone the row from a template you keep on the side, eg:

    $( #RowTemplate tr ).clone(true).show() 
    
  3. Another option is to copy the row when the page is loaded, and then recloning it:

    var rowTemplate = $( #picTableDisplay tbody>tr:last ).clone(true)
    
    $( #picTableDisplay tr ).click(function(){
       $(this).closest( tr ).remove();
       var row = rowTemplate.clone(true) //...
    });
    

Please also note there s a known bug with cloning the last element on IE, as detailed here: Problem using jQuery clone function in form.

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签