PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Jquery教程 > 正文

    jquery 复制文字到剪贴板

    作者:admin来源:网络浏览:时间:2020-10-30 20:05:51我要评论
    导读:复制文字到剪贴板<html><buttonclass="copy"type="submit">复制链接</button><script>functioncopyText(text){vartextarea=document.create...
    复制文字到剪贴板

    1. <html> 
    2. <button class="copy" type="submit"
    3.     复制链接 
    4. </button> 
    5. <script> 
    6.     function copyText(text) { 
    7.         var textarea = document.createElement("textarea"); 
    8.         var currentFocus = document.activeElement; 
    9.         document.body.appendChild(textarea); 
    10.         textarea.value = text; 
    11.         textarea.focus(); 
    12.         if (textarea.setSelectionRange) 
    13.             textarea.setSelectionRange(0, textarea.value.length); 
    14.         else 
    15.             textarea.select(); 
    16.         try { 
    17.             var flag = document.execCommand("copy"); 
    18.         } catch(eo){ 
    19.             var flag = false
    20.         } 
    21.         document.body.removeChild(textarea); 
    22.         currentFocus.focus(); 
    23.         return flag; 
    24.     } 
    25.     $(".copy").on('click',function(){ 
    26.         var text='复制的文字'
    27.         var flag = copyText(text); 
    28.         alert(flag ? "复制成功!" : "复制失败!"); 
    29.     }); 
    30. </script> 
    31. </html> 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-47-6405-1.html
    相关热词搜索: jquery复制 jquery剪贴