简体   繁体   中英

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. 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.

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.

How can I do this?

无效: prompt()为单行。

您可以使用Ctrl + C (至少在Windows上)复制对话框的内容(例如JavaScript中的alert() )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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