我正在尝试在新行中立即将文本复制到剪贴板。当然,当我单击复制按钮然后将其粘贴到(帖子、网站、博客、论坛、记事本等)时,它会与您复制它的位置相同。 更多解释:
这是我复制前的样子
Some commonly sold digital good include:
1- eBooks.
2- Audiobooks.
3- Pictures and Videos.
4- Digital Music.
5- Software programs.
但是,当我将它复制并粘贴到记事本中时,它只会像这样出现在一行中
Some commonly sold digital good include:1- eBooks.2- Audiobooks.3- Pictures and Videos.4- Digital Music.5- Software programs.
这里是我说的 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();
});
});
如果可能的话,我希望文本看起来像我们第一次复制它时的样子
最佳答案
只是改变:
var $temp = $("<input>");
收件人:
var $temp = $("<textarea>");
关于javascript - 如何使用 br 断行制作(复制到剪贴板),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50179008/