一键复制功能对于下载站十分重要,下面介绍如何添加一键复制功能。
引入JS:
<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" type="text/javascript"></script>
PHP代码如下,替换想要复制的内容,CSS代码自行控制:
<button id="TKLS" class="itemCopy red_tkl button_tkl" type="button" data-clipboard-text="想要复制的内容">一键复制</button>
JS代码如下:
<script>
var clipboard = new ClipboardJS('.itemCopy');
clipboard.on('success',
function(e) {
if (e.trigger.disabled == false || e.trigger.disabled == undefined) {
e.trigger.innerHTML = "复制成功";
e.trigger.disabled = true;
setTimeout(function() {
e.trigger.innerHTML = "一键复制";
e.trigger.disabled = false;
},
2000);
}
});
clipboard.on('error',
function(e) {
e.trigger.innerHTML = "复制失败";
});
</script>
© 版权声明
THE END
暂无评论内容