html
<textarea cols="20" rows="10" id="tkl">
复制内容
</textarea>
<input type="button" onClick="copyTkl()" value="复制" />
js
function copyTkl() {
const range = document.createRange();
range.selectNode(document.getElementById('tkl'));
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制淘口令成功......");
}
网友评论