js实现复制功能
作者:
web前端技术 | 来源:发表于
2020-05-23 19:24 被阅读0次
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("复制淘口令成功......");
}
本文标题:js实现复制功能
本文链接:https://www.haomeiwen.com/subject/vtblahtx.html
网友评论