【发布时间】:2021-08-04 06:26:36
【问题描述】:
我正在使用模板引擎,并以我能做到的唯一方式传递一个变量,但是这个变量的输出是一个数组,它出现在同一行中,没有中断。
<div>
<h4>Questions</h4>
<span id="question">
How was your day?,Could you finish it?
</span>
</div>
所以这就是它的外观,我不能简单地编辑 span 文本,如果渲染后不查看它,我的 span 内部代码是空的。
我想做这样的事情:
$( "#question" ).replaceWith( this.text().replace(/,/g, '<br>'));
这可能吗?
【问题讨论】:
-
您确定要使用
replaceWith()吗?这将删除question跨度,以便文本直接位于<div>中。
标签: javascript jquery arrays performance