document.addEventListener('touchend', touch, false);

function touch(event){
    var node = document.createElement('textarea');
    node.value = '测试文本';
    node.setAttribute('readOnly','readOnly');
    node.setAttribute('style',"position: fixed; left: 0; top: 0;opacity: 0");
    document.getElementsByTagName('body')[0].appendChild(node);
    setTimeout(function() {
        node.focus();
        node.setSelectionRange(0, node.value.length);
        try{
            document.execCommand('copy', true);
        } catch(e) {}
        node.parentNode.removeChild(node);
    }, 0);
}

移动端基本都支持,UC不支持。

posted on 2018-01-12 17:01  ystrdy  阅读(437)  评论(0编辑  收藏  举报