点击复制有三种方式两种插件另一种是原生的写(我比较建议用原生写)

目前关于点击复制的插件我知道的有ZeroClipboard.Core.jsclipboard.min.js

ZeroClipboard.Core.js

看了好多这个依附于flash

clipboard.min.js

安卓手机没问题,测试苹果六不兼容点击没反应

上代码

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="sourceText" style="position: fixed; top:-200px;" >
<div onclick="copywx()">点击复制</div>
<script>
var sourceText = document.getElementById('sourceText');
sourceText.preventDefault=false;
document.activeElement.blur();
sourceText.value=stxlwx;

function copywx(){
var currentFocus = document.activeElement;
sourceText.focus();
sourceText.setSelectionRange(0, sourceText.value.length);
document.execCommand('copy', true);
sourceText.blur();
confirm('微信号'+stxlwx+'复制成功');
}
</script>
</body>
</html>

版权声明:本文为liying249847原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/liying249847/p/10161905.html