function copy(){
var tb = document.getElementById('table');
var tr = document.querySelectorAll("#table tr:last-of-type td").value;
alert(tr);
var copyalbe = tr;
var input = document.createElement("input");
input.value = copyalbe;
document.body.appendChild(input);
input.select();
document.execCommand("copy");
input.style.display = "none";
alert("复制成功");
}
<table id="table" width="200" border="1" cellspacing="0">
<tr id="cow1">
<td>123</td>
<td>111</td>
</tr>
<tr id="cow2">
<td>123</td>
<td>111</td>
</tr>
<tr id="cow3">
<td class="copyalbe">123</td>
<td class="copyalbe">111</td>
</tr>
</table>
<input id="btn" type="button" value="复制" onclick="copy()">
我想要获取table中最后一个tr里的两个td的值并复制,但不知道如何获取值,有老哥们指教下吗?
皈依舞
相关分类