JavaScript实现选中文字自动复制

<script>
//获取复制区域id
var oContent =document.getElementById('txtbox');
oContent.onmouseup = function(){
alert(selectText());
};  
function selectText(){
if(document.Selection){       
//ie浏览器
return document.selection.createRange().text;     	 
}else{    
//标准浏览器
return window.getSelection().toString();	 
}	 
}	
var oContent =document.getElementById('txtbox');
oContent.onmouseup = function(){
document.execCommand("Copy");	
};  
</script>
原文地址:https://www.cnblogs.com/xinlvtian/p/12035402.html