需要一个JS
下载地址:官方下载,使用dist/clipboard.min.js就好
demo
<script type="text/javascript" src="./statics/jquery.js"></script> <script type="text/javascript" src="./statics/clipboard.min.js"></script> <button class="public-name" data-clipboard-text="">aaaaaabbbbbbbbbbb</button> <script> $(document).ready(function() { <!-- copy func --> var clipboard = new Clipboard('.public-name'); clipboard.on('success', function(e) { alert("ok"); }); clipboard.on('error', function(e) { alert("error"); }); $(".public-name").attr("data-clipboard-text", "123123"); }); </script>
MD好像不行了,