<span id=
"codeNum">FTYHDSDW</span>
<span
class=
" code-btn" id=
"codeBtn" data-clipboard-target=
"#input">复制</span>
js代码
<script type=
"text/javascript">
function copyArticle(event) {
const range =
document.createRange();
range.selectNode(document.getElementById('codeNum'));
const selection =
window.getSelection();
if(selection.rangeCount >
0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}
document.getElementById('codeBtn').addEventListener(
'click', copyArticle,
false);
</script>
源地址:https://www.jianshu.com/p/6ec9c72dc5eb
转载于:https://www.cnblogs.com/opcec/p/11578384.html
相关资源:移动端js 点击按钮复制到粘贴