[英]How do I format a string to be multi-line in a JavaScript prompt?
I'm trying to offer the user multi-line selectable text using a prompt()
dialog. 我正在尝试使用prompt()
对话框为用户提供多行可选文本。 I will format the text in JavaScript, insert special characters and then throw up the prompt and all the user has to do is hit Ctrl-C, because the text is already selected. 我将使用JavaScript设置文本格式,插入特殊字符,然后抛出提示,所有用户所需要做的就是按Ctrl-C,因为已经选择了文本。
When the prompt is displayed, the selectable text will look like this: 显示提示时,可选文本如下所示:
Line1□Line2□Line3□
where the □
is the newline character. □
是换行符。 It all gets displayed in one line, so it's easily selectable, but pasting it into Notepad or any other text editor should result in this: 它们全部显示在一行中,因此很容易选择,但是将其粘贴到记事本或任何其他文本编辑器中应该会导致以下结果:
Line1
Line2
Line3
I tried \\r
and \\n
and even \\r\\n
, but it seems to truncate it to the first line. 我尝试了\\r
和\\n
甚至\\r\\n
,但似乎将其截断到第一行。
How can I do this? 我怎样才能做到这一点?
无效: prompt()
为单行。
您可以使用Ctrl + C (至少在Windows上)复制对话框的内容(例如JavaScript中的alert()
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.