我非常喜欢在我的网站上复制到剪贴板,这里是我感兴趣的示例。
(function() {
"use strict";
function copyToClipboard(elem) {
var target = elem;
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch (e) {
console.warn(e);
succeed = false;
}
// Restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
if (succeed) {
$(".copied").animate({
top: -25,
opacity: 0
}, 700, function() {
$(this).css({
top: 0,
opacity: 1
});
});
}
return succeed;
}
$("#copyButton, #copyTarget").on("click", function() {
copyToClipboard(document.getElementById("copyTarget"));
});
}());
这是代码笔https://codepen.io/LattyS/pen/QvGyKL
但我有两个问题
- 如果我单击任何一个将它们全部复制在一起,则尝试制作多个链接时。
- 如何也可以创建 DIV
所以我需要同时创建 10 个以上的链接,如果有能力使用 DIV 复制到剪贴板,或者不能使用同一个项目?像图片中的这个https://gulfupload.com/i/00025/fq8kg0ef7gw6.png