js+html5实现复制文字按钮
<div>
<input type="text" name="guanfangaddress" id="guanfangaddress"/>
<span id="copyBT" >复制</span>
</div>
<script type="text/javascript">
function copyArticle(event) {
const range = document.createRange();
range.selectNode(document.getElementById('guanfangaddress'));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}
document.getElementById('copyBT').addEventListener('click', copyArticle, false);
</script>