实现邀请码的复制粘贴
一、点击input框进行复制
function copy(message) { var input = document.createElement("input"); input.value = message; document.body.appendChild(input); input.select(); input.setSelectionRange(0, input.value.length), document.execCommand('Copy'); document.body.removeChild(input); //alert("复制成功"); }
二、点击按钮复制文本
邀请码复制
function copyArticle(event) {
const range = document.createRange();
range.selectNode(document.getElementById('content'));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
var content=$("#content").html();
if(content != "" && content != null && content != undefined){
alert("复制成功!");
}
}
document.getElementById('copyBT').addEventListener('click', copyArticle, false);