纯JS实现,支持移动端和PC。clipboard.js
- 引入clipboard.js
<script type="text/javascript" src="/public/js/clipboard.min.js"></script>
- html
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
![](assets/clippy.svg)
</button>
- JS
<script type="text/javascript">
var clipboard = new Clipboard('.btn');
</script>
具体可以查看官网的例子
https://clipboardjs.com/
https://github.com/zenorocha/clipboard.js