1、直接利用js的execCommand,此方法移动端无效
<input type="text" id="url" readonly class="form-control" name="url" placeholder="Email to:" value="<?= $sharelink ?>">
<button onClick="url.select();document.execCommand('Copy');alert('复制成功')" class="btn btn-primary btn-block"><b>复制链接</b></a>
2、引入js插件clipboard.js
<!-- 1. Define some markup -->
<div>hello</div>
<button class="btn" data-clipboard-action="copy" data-clipboard-target="div">Copy</button><!-- 2. Include library --> <script src="../dist/clipboard.min.js"></script> <!-- 3. Instantiate clipboard --> <script> var clipboard = new ClipboardJS('.btn'); clipboard.on('success', function(e) { console.log(e); }); clipboard.on('error', function(e) { console.log(e); }); </script>