javascript-复制
Posted 青草圆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript-复制相关的知识,希望对你有一定的参考价值。
cefCopy:function(str){ var t=this; if(!str || str=="暂无激活码") { $.notice("暂无激活码", ‘error‘); return; } if(!t.$$text){ t.$$text = $("<textarea/>").css({ position:"absolute", "left":"-1000px", "top":"-1000px" }).appendTo("body"); } t.$$text.text(str).focus(); var em = t.$$text[0]; em.setSelectionRange(0, em.value.length); //选中文字 setSelectionRange光标的起始结束位置 var rlt; try { rlt = document.execCommand("Copy"); //window.execCommand是兼容ie的 document是兼容谷歌 选中文字到剪贴板 } catch (n) { rlt = !1 } if(rlt){ $.notice("复制成功", ‘success‘); }else{ $.notice("复制失败", ‘error‘); } return rlt; }
以上是关于javascript-复制的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段12——JavaScript的Promise对象