简体   繁体   中英

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

Any ideas how to fix this?

I also tried 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

Regards Marwan

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