html :
<body>
<div class="demo-area">
<label for="copy-input">输入要复制到剪切板的文字:</label><br>
<textarea id="copy-input" cols="30" rows="10"></textarea><br>
<button id="copy-button">复制到剪贴板</button><br>
</div>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="path/to/ZeroClipboard.js"></script>
</body>
</html>js:
//配置ZeroClipboard.swf
ZeroClipboard.config({
swfPath: ‘./vendor/ZeroClipboard.swf‘
});
//初始化
var client = new ZeroClipboard(document.getElementById("copy-button"));
client.on("ready", function(readyEvent) {
client.on("copy", function(event) {
var clipboard = event.clipboardData;
var copyText = $(‘#copy-input‘).val();
clipboard.setData("text/plain", copyText); // 将内容添加到剪切板
});
});
兼容主流浏览器的最终解决方案
将内容复制到剪切板兼容主流浏览器的解决方案
时间: 2024-12-21 20:53:19