简体   繁体   English

你如何做一个 <textarea> 知道按Enter键是\\ n字符?

[英]How do you make a <textarea> recognize that pushing the enter button is a \n character?

I have a <textarea> that I want to print the contents on the page below it. 我有一个<textarea> ,我想在其下面的页面上打印内容。 When it does this I want to make random words be omitted. 这样做时,我想省略随机单词。

I have accomplished this. 我已经做到了。 My problem is I want make it recognize when the enter button has been pushed in the <textarea> and display that below. 我的问题是我想让它识别<textarea>的输入按钮何时按下,并在下面显示。 I want those to not ever be omitted. 我希望这些内容永远不会被忽略。 I have gotten it so that when a <br/> is typed into the <textarea> it will not omit those and it will show the new lines. 我知道了,这样当在<textarea>键入<br/>时,它不会忽略那些内容,并且会显示新行。 When I tried doing that with the \\n it does not seem to recognize in the .value of the object that the enters are \\n . 当我尝试使用\\n时,似乎在对象的.value中无法识别出输入为\\n

Any ideas how to fix this? 任何想法如何解决这一问题?

I also tried var txtAdd = document.getElementById('textLoc').value.replace("\\n","<br/>"); 我还尝试了var txtAdd = document.getElementById('textLoc').value.replace("\\n","<br/>"); and it did not work. 它没有用。

也许是“ .replace(/ \\ n / g,'<br />');”?

我没有遵循您的尝试,但是是否有可能需要\\ r \\ n,因为这等效于Windows计算机上的换行符(假设您正在运行Windows)?

I think its about way of saving the data first time you should use innerHTML property that you can save it with with out replacing with \\n 我认为这是有关第一次保存数据的方式,您应该使用innerHTML属性,该属性可以保存而无需用\\ n替换

Regards Marwan 问候马万

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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