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;
}