确认框中换行
我想在我的警报框中有两行
现在我有以下内容:
<%= link_to 'back', 'history.back()', :confirm => 'Are you sure? This is my second line' %>
我尝试添加 '\n' 但它不起作用,它只是在我的文本之间写入 \n。我应该怎么办?
先感谢您
I want to have two lines in my alert box
Right now I have the following:
<%= link_to 'back', 'history.back()', :confirm => 'Are you sure? This is my second line' %>
I have tried adding '\n' but it is not working, it just writes \n between my text. What should I do?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为确认文本周围的单引号导致
\n
按字面解释。试试这个:I think the single quotes around your confirm text are causing the
\n
to be interpreted literally. Try this:如果您想要多行确认/警报语句,则需要使用双引号。
单引号不会转换您的新换行符\n
这可以工作:
:确认=> “您将\n删除所有跟踪信息。\n您确定吗?”
希望这有帮助;)
If you want a multi-line confirm/alert statement, you will need to use double quote.
Single quote will not convert your new line feed \n
This would work:
:confirm => "You are about to \n DELETE all tracking information.\nAre you sure?"
Hope this helps ;)
JavaScript 警报框中的新行 您需要阻止 Rails 转义新行在生成的 HTML 表单中。您可以尝试
<%= link_to 'back', 'history.back()', :confirm =>原始'你确定吗? \n 这是我的第二行' %>
New line in JavaScript alert box You need to stop rails from escaping the new line in the generated HTML form. Can you try
<%= link_to 'back', 'history.back()', :confirm => raw 'Are you sure? \n This is my second line' %>