[英]How to put newlines in JavaScript window.prompt?
I want to put selected text a user can select in a prompt. 我想在用户提示中输入选定的文本。
function copyToClipboard (text) {
window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}
The problem with this is that the text may have newlines. 问题在于文本可能包含换行符。 In that case, I only see the first line of the text. 在这种情况下,我只会看到文本的第一行。 Is there anyway I can insert newlines or maybe have a custom prompt that allows this? 无论如何,我可以插入换行符,或者有一个允许这样做的自定义提示吗? Thanks. 谢谢。
window.prompt
won't be capable of doing that, perhaps you should look at a more convenient (and better) approach: window.prompt
将无法执行此操作,也许您应该考虑一种更方便(更好)的方法:
How do I copy to the clipboard in JavaScript? 如何使用JavaScript复制到剪贴板?
The new line thing --> \\n
新行-> \\n
So what you will do is simply type: 因此,您只需输入以下内容即可:
prompt("Hello world,\\nA newline!", [default text]);
And about the custom prompt
thing, there is no such thing in W3C . 而且关于custom prompt
事情,在W3C中没有这样的事情 。 However, it does have a similar thing called the Modal Dialog , which is just a new window containing a website in it. 但是,它确实有一个类似的东西,叫做“ 模态对话框” ,它只是一个新窗口,其中包含一个网站。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.