我正在尝试实现使用换行符将文本复制到剪贴板,然后将其粘贴到 Windows 下的简单文本文件中:
function copyText(name, value){
var text = name + ': ' + value + '\r\n';
var text += 'next line';
if (document.body.createTextRange){
var cont = document.createElement('p');
var textNode = document.createTextNode(text);
cont.appendChild(textNode);
document.body.appendChild(cont);
var textRange = document.body.createTextRange();
textRange.moveToElementText(cont);
textRange.execCommand('copy');
document.body.removeChild(cont);
}
}
但是插入文件后没有换行符。如何解决?
最佳答案
看看这是否有效:
var cont = document.createElement('pre');
关于javascript - JS : insert a line break into copied text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49549556/