javascript - 使从绝对定位的 div 复制的文本保留空格
问题描述
我正在实现 OCR,我需要在图像顶部呈现已识别的文本。我使用绝对定位的 div。每个词的每个 div。当我选择一个句子并复制它时购买,所有的空格都消失了。
我怎样才能让它用空格复制?
const words = ["lorem", "ipsum", "dolor", "sit", "amet"];
const container = document.getElementById("words");
let i = 0;
for (const w of words) {
const el = document.createElement("div");
el.innerText = w;
el.style.width = 30 + "px";
el.style.height = 10 + 'px';
el.style.top = (i * 10) + "px";
el.style.left = (i * 40) + "px";
i += 1;
container.appendChild(el);
const space = document.createElement("span");
space.innerHtml=" ";
el.appendChild(space);
}
这是一个例子:https ://codepen.io/konstantin-edward-alikhanov/pen/YzpeNwV?editors=0110
解决方案
将反引号与ES6 模板文字一起使用。
el.innerText = w + ` `;
推荐阅读
- javascript - 如果条件使用 React Router V4 更改路由
- r - 如何在 R 中的给定数据框中找到每月平均支出?
- sql - 在 SQL 查询中尝试/捕获多个联合
- image - 在八度音阶的 ylabel 中打印带下标的绘图时间距没有错
- sql - SQL 将 varchar 转换为日期
- qt - qmake没有蓝牙
- javascript - 反应:WEBPACK:构建到 PROD,在 SourceMap 中显示本地机器路径
- azure - 如何将自定义域名与 Azure ARM 模板部署绑定
- angular - 将角料片添加到输入框
- c# - 反序列化从 Azure 表中检索到的 DynamicTableEntity