https://jsfiddle.net/boc58L0j/3/
https://jsfiddle.net/boc58L0j/9/
<table>
<tr>
<td>文字一</td>
<td><input type="button" value="複製" onclick="copy('文字一');"/>
</td>
</tr>
<tr>
<td>文字二</td>
<td><input type="button" value="複製" onclick="copy('文字二');"/>
</td>
</tr>
</table>
function copy(strInpt) {
//新增
var textArea = document.createElement("textarea");
textArea.value = strInpt;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("Copy");
textArea.remove();
// Alert the copied text
alert("Copied the text: " + strInpt);
}
function copy(strInpt) {
//新增
var copyText = document.createElement("textarea");
copyText.value = strInpt;
document.body.appendChild(copyText);
copyText.select();
//copyText.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
copyText.remove();
// Alert the copied text
alert("Copied the text: " + strInpt);
}
沒有留言:
張貼留言