1.首先引入js文件,
<script src="dist/clipboard.min.js"></script>
2.初始化
<script type="text/javascript">
$(function(){
new Clipboard('.copyurl');
});
function copyUrl() {
if (window.clipboardData) {
window.clipboardData.clearData();
var clipBoardContent = '<%= this.lblDownFileUrl.Text %>';
window.clipboardData.setData("Text", clipBoardContent);
}
}
</script>
3.使用方式一
<a class="copyurl" data-clipboard-text="Copy to clipboard" href="javascript:void(0);" onclick="copyUrl();" >复制链接</a>
4.使用方式二
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git"> <!-- Trigger -->
<button class="copyurl" data-clipboard-target="#foo"> <img src="assets/clippy.svg" alt="Copy to clipboard"> </button>
From:https://github.com/zenorocha/clipboard.js
https://clipboardjs.com/