點擊按鈕復制文本,文本可以不用顯示,同時支持各種手機端;
方便制作淘寶客鏈接,可同時展示多個按鈕
<div align="center">
<div id="shop1" style=" font-size:0;">¥3EVabwQtX01¥</div>
<input type="button" value="優農宣威" onclick="copyText('shop1')" />
</div>
<script type="text/javascript">
function copyText(shop) {
const range = document.createRange();
range.selectNode(document.getElementById(shop));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("復制成功!打開手機淘寶即可查看");
}
</script>
