第一种使用clipboard:
上面也说了,已经迁移到clipboard-polyfill
兼容性:
第二种使用clipboard-polyfill:
github地址:https://github.com/lgarron/clipboard-polyfill
兼容性:
第三种使用原生JS
HTML
<button onClick="copy('把内容读到这里')" >
复制链接
</button>
JS
<script>
function copy(message) {
var input = document.createElement("input");
input.value = message;
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, input.value.length), document.execCommand('Copy');
document.body.removeChild(input);
}
</script>