我不想使用Flash,但要使用新的HTML5剪贴板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();
}
执行于 click
$('.link-copy').on('click', function() {
copyContent('#p');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句