使用 jquery 在特定 <td> 标签之间复制数据

Copy data between specific <td> tags using jquery

我有一个 table 这样的:

<table>
<tr>
   <td class="type">Order</td>
   <td class="orderid">1002</td>
   <td><button class="copy">Copy Row</button></td>
</tr>
<tr>
   <td class="type">Order</td>
   <td class="orderid">1004</td>
   <td><button class="copy">Copy Row</button></td>
</tr>
<tr>
   <td class="type">Refund</td>
   <td class="orderid">1004</td>
   <td><button class="copy">Copy Row</button></td>
</tr>
</table>

我有一个脚本可以从特定的“#id”或“.class”元素复制数据。我需要的是找到一种方法来在按下“复制”按钮时获取该特定行的数据。我想要复制该特定行的列 'orderid' 和 'type' 值,但我无法找到一种方法来提取具有相同 [=] 的 <td> 标签之间的数据20=] 名字。

     <tr>
       <td class="type">Refund</td>
       <td class="orderid">1004</td>
       <button class="copy">Copy Row</td>
     </tr>


     $(".copy").click(
           function(event)
           {
             var copy=($(event.target).parent().find('.type'));
             var order=($(event.target).parent().find('.orderid'));
           }
         );

您必须将复制的日期粘贴到某处。将此副本和订单作为全局变量。单击粘贴时,使用此变量的值

看看这个fiddlehttp://jsfiddle.net/3p29x2s9/11/

var buttons=document.getElementsByClassName("copy");
console.log(buttons);
for(var i=0;i<buttons.length;i++){
buttons[i].onclick=function(){
    var columns = this.parentElement.parentElement.getElementsByTagName("td");
    var type= columns[0].innerText;
    var orderid=columns[1].innerText;
 alert(type + " "+orderid);   

}
}

简单回答:

      $('.copy').click(function(){
      var order_id =  $(this).parent().parent().find('.orderid').text();
      var type =  $(this).parent().parent().find('.type').text();
         alert(order_id);  ///this wil get you the value
      });

我在这里做了结果:http://codepad.viper-7.com/ahsVfB

检查一下。