html :
js:<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="/jquery/1.9.0/jquery.js"></script><script src="path/to/ZeroClipboard.js"></script></body></html>
//配置ZeroClipboard.swfZeroClipboard.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); // 将内容添加到剪切板});});
兼容主流浏览器的最终解决方案
使用ZeroClipboard。