复制粘贴
function copyText(){
var CopyBtn=document.getElementById('CopyBtn');
var $=function(id){return "string" == typeof id ? document.getElementById(id) : id;};
var start, end, obj, data;
obj = $("copyText");
console.log(obj.value);
data = obj.value;
end = data.length;
CopyBtn.onclick = function(){
if(-[1,]){ //处理费IE浏览器
obj.setSelectionRange(0,end);
obj.focus();
document.execCommand("Copy");
alert("复制成功");
}else{
if(window.clipboardData){
var flag = window.clipboardData.setData("text",data);
if(flag == true){
alert("复制成功。");
}else{
alert("复制失败。");
}
}else{
alert("您使用的浏览器不支持此复制功能,请使用Ctrl+C或鼠标右键。");
obj.setSelectionRange(0,end);
obj.focus();
document.execCommand("Copy");
}
}
}
}