0

我正在尝试用字符串填充手风琴 div。我正在尝试在我的字符串中添加换行符,但由于某种原因,在我的手风琴中,换行符不起作用

<%str = " "%>
<% user.costs.last(3).each do |cost| %>
    <%str += cost.description + " " + cost.value.to_s + " " + "\n"%>
<%end%>
<p><%=str %> </p>

我在发布之前检查了这个

4

1 回答 1

2

换行实际上不会在 HTML 中换行(特殊情况除外,例如<pre>标签):

<p>this
is
a
test</p>

将呈现为:

这是一个测验

在实时页面上查看

如果要换行,请使用<br/>换行标记:

<%str += cost.description + " " + cost.value.to_s + " " + "<br/>"%>

另外,使用原始字符串(所以<不要>转义):

<p><%=raw str %></p>
于 2013-10-28T01:44:07.700 回答