点击复制有三种方式两种插件另一种是原生的写(我比较建议用原生写)
目前关于点击复制的插件我知道的有ZeroClipboard.Core.js和clipboard.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 οnclick="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>