html 一鍵復制


 //一鍵復制
        $("#b_identifier").click(function() {
            var ssrsss = $(".label-content").attr('title');//獲取文本
            var flag = copyText(ssrsss); //傳遞文本
            flag ? layer.msg('復制成功!', {icon: 1}) : layer.msg('復制失敗!', {icon: 2});
        })
        function copyText(text) {
            var textarea = document.createElement("input");//創建input對象
            var currentFocus = document.activeElement;//當前獲得焦點的元素
            document.body.appendChild(textarea);//添加元素
            textarea.value = text;
            textarea.focus();
            if(textarea.setSelectionRange)
                textarea.setSelectionRange(0, textarea.value.length);//獲取光標起始位置到結束位置
            else
                textarea.select();
            try {
                var flag = document.execCommand("copy");//執行復制
            } catch(eo) {
                var flag = false;
            }
            document.body.removeChild(textarea);//刪除元素
            currentFocus.focus();
            return flag;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM