首页 > 解决方案 > 将换行符添加到复制缓冲区

问题描述

我不知道如何将换行符添加到复制缓冲区,然后可以将其粘贴到带有断行的谷歌表格中。我需要一个 HTML (br / p) 行为。当我们选择带有此类换行符的文本并在表单中逐行传递时。

我不想为此创建一个新窗口:

 let string="";
 document.querySelectorAll('p').forEach(el => {string+= el.innerText + "<br/>"});
 let newWin =  window.open("", "Title");
    newWin.document.body.innerHTML=string;
    newWin.getSelection().selectAllChildren(newWin.document.body);
    newWin.execCommand("copy");
 }

标签: javascript

解决方案


推荐阅读