复制内容到剪切板

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<p><span ondblclick="copy(this)" style="" >operations@rccbermuda.bm</span></p>
	</body>
	<script>
		function copy(that) {
    
    
			that.style.background = '#efe78280';
			var text = that.innerText;
		    var textareaEl = document.createElement('textarea');
		    textareaEl.setAttribute('readonly', 'readonly'); // 防止手机上弹出软键盘
		    textareaEl.value = text;
		    document.body.appendChild(textareaEl);
		    textareaEl.select();
		    var res = document.execCommand('copy');
		    document.body.removeChild(textareaEl);
		    setTimeout(function(){
    
    
		    	alert("复制成功!");
		        that.style.background = '';
		    },800)
		    return res;
		}
	</script>
</html>

参考链接:https://www.cnblogs.com/zhaodesheng/p/11464934.html

おすすめ

転載: blog.csdn.net/yiyueqinghui/article/details/114025060
おすすめ