clone然后在用jquery插回之前改变表行

Sle*_*lee 1 jquery

我有2个表,其中有一个可供选择的产品列表和一个选择了产品的产品.我也有一个链接,从一个添加,从另一个删除.当你从其中一个表中删除我要复制并插入到另一个表中时,我需要在执行此操作之前更改链接href,然后向其添加单击行为.

这是我克隆的表格行.

<tr> 
        <td><a href="/Partner/DeleteProduct/41/?ProductID=935ad105-xxxx-xxxx-xxxx-659cd4c55ec7"  class="delete"><img src="/Content/images/remove.png" alt="Delete" /></a> <span id="705">GastroMend-HP </span></td> 
        <td>Designs for Health</td> 
</tr> 
Run Code Online (Sandbox Code Playgroud)

这是我的代码到目前为止,它正确地移动行但值得错误的链接href,虽然我确实正确地改变了我想要的img路径(#Product是我要添加的表).

$('a.delete').click( function(e){
var el = $(this)
  // hide the clicked row
  el.parent().parent().fadeOut();
      // this does my server work
      $.get(el.attr('href'), function(data) {
          // this is the row cloning part I need to tweak
          el.parent().parent().clone().insertAfter('#Product tr:first').find('img').attr('src','/Content/images/insert.png');
      });
  e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

use*_*716 7

将其存储在变量中,然后在插入之前对其进行操作.

var myclone = el.parent().parent().clone();

myclone.find('img').attr('src','/Content/images/insert.png');
myclone.find('a').attr('href','http://....');

myclone.insertAfter('#Product tr:first');
Run Code Online (Sandbox Code Playgroud)