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>
posted @ 2019-12-13 15:33  绿林豪士  阅读(714)  评论(0编辑  收藏  举报