js 以及 angular 2+ 实现复制(拷贝)功能
js原生方法
//方法一:如果copyObject是一个input或者textarea
function copyOne(){
var copyInnerHTML = document.getElementById('copyObject');
copyInnerHTML.select();
document.execCommand('copy');
}
//方法二:div类型
function copyTwo(){
const range = document.createRange();
range.selectNode(document.getElementById('copyInner'));
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy'