繁体   English   中英

您将如何添加非中断空间等。 在文中?

[英]How would you add non breaking space and ect. in the text?

目标是显示这样的字符串:

苹果、香蕉、柠檬

假设它在一个数组中。

const fruits = ['Apple', 'Banana', 'Lemon']

  1. 我想用逗号和空格加入这个数组。 你会怎么做?

新设计来了,他们想展示

苹果、🤩香蕉、🤩柠檬

结合逗号,双 nbsp 和表情符号。

  1. 您将如何重构第一个实现?

如果你想添加 HTML,你应该正确地创建它。 定义一个包装器并迭代数组中的项目以将它们添加到其中。

至于空格,添加空格字符从来都不是一个好主意。 如果要在元素之间创建空间,请使用 CSS padding / margins

 const array = ['Apple', 'Banana', 'Lemon']; const wrapper = document.createElement("div"); for (const item of array) { const itemWrapper = document.createElement("span"); itemWrapper.classList.add('space'); itemWrapper.innerText = item; wrapper.append(itemWrapper); } document.documentElement.append(wrapper);
 .space { margin-right: 1em; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM