我不想使用 flash,而是使用新的 HTML5 Clipboard API。
我想通过点击$('.link-copy')
来触发复制事件
我该怎么做?我似乎找不到有效的示例。
最佳答案
以下是如何执行此操作的一个非常基本的示例:
HTML:
<p id="p">Some random text</p>
JavaScript:
copyContent = function (el) {
// Create a temporary element
var $tmp = $("<input />");
// Add the temp el to the DOM
$("body").append($tmp);
// Add the text to the temp el and select it
$tmp.val($(el).text()).select();
// Tell the broswer to copy the selection
document.execCommand("copy");
// Remove the temporary element
$tmp.remove();
}
点击执行
$('.link-copy').on('click', function() {
copyContent('#p');
});
关于jquery - 通过单击 jQuery DOM 使用 HTML5 剪贴板 API 复制到剪贴板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33614369/