我正在尝试在新行中立即将文本复制到剪贴板。当我点击复制按钮然后将其粘贴(帖子,网站,博客,论坛,记事本等)时,它将与您复制它的位置相同。 更多解释:
这是我复制之前的文字
Some commonly sold digital good include:
1- eBooks.
2- Audiobooks.
3- Pictures and Videos.
4- Digital Music.
5- Software programs.
然而,当我将其复制并粘贴到记事本中时,它只会出现在这样的一行
中一些常见的数字商品包括:1-电子书.2-有声读物3- 图片和视频.4-数字音乐.5-软件程序。
这是我正在谈论的JS。
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
var addrsField = $('.input_copy .txt');
$('.input_copy .icon').click(function() {
copyToClipboard('.input_copy .txt');
addrsField.addClass('flashBG').delay('1000').queue(function(){
addrsField.removeClass('flashBG').dequeue();
});
});
如果可能的话,我希望文本在我们第一次复制时看起来像
以下是codepen https://codepen.io/null000/pen/wjqYVN
答案 0 :(得分:0)
只需改变:
var $temp = $("<input>");
致:
var $temp = $("<textarea>");