粘贴复制

匿名 (未验证) 提交于 2019-12-02 23:38:02

方法二:

方法三:

// 第三种 ios 设备和 android设备均正常,但是pc端没有//定义函数window.Clipboard = (function(window, document, navigator) {    var textArea,        copy;    // 判断是不是ios端    function isOS() {        return navigator.userAgent.match(/ipad|iphone/i);    }    //创建文本元素    function createTextArea(text) {        console.log(text,"text");        textArea = document.createElement('textArea');        console.log(textArea,"textArea");        textArea.innerHTML = text;        textArea.value = text;        console.log(textArea.value,"textArea.value");        document.body.appendChild(textArea);    }    //选择内容    function selectText() {        var range,            selection;        if (isOS()) {            range = document.createRange();            range.selectNodeContents(textArea);            selection = window.getSelection();            selection.removeAllRanges();            selection.addRange(range);            textArea.setSelectionRange(0, 999999);        } else {            textArea.select();        }    }    //复制到剪贴板    function copyToClipboard() {        try{            if(document.execCommand("Copy")){                Toast("复制成功!",1000);            }else{                Toast("复制失败!请手动复制!",1000);            }        }catch(err){            Toast("复制错误!请手动复制!",1000);        }        document.body.removeChild(textArea);    }        copy = function(text) {            createTextArea(text);            selectText(text);            copyToClipboard(text);        };        return {            copy: copy        };     })(window, document, navigator);//使用函数$("#copy").on("click",function(){    var  val = $("#textAreas").val();    console.log("val",val)    Clipboard.copy(val);});方法四:
 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!