JavaScript

//原生copy, 入参为 id 属性的值
function copy(data) {
    let text = $("#" + data).val();
    var input = document.createElement('input');
    input.setAttribute('readonly', 'readonly');
    input.setAttribute('value', text);
    document.body.appendChild(input);
    input.select();
    input.setSelectionRange(0, 9999);
    document.execCommand('Copy');
    //移除
    input.remove()
    layer.msg('复制成功!',{icon: 1, offset: '210px'});

}
posted @ 2021-05-10 21:29  那年长安  阅读(29)  评论(0编辑  收藏  举报