简体   繁体   中英

textarea saved with break lines cannot be returned as created to the front-end of my project , how to resolve that?

I have an html form where I have a textarea box: my process is to create a text in the textarea then click on the save button, after the save the content of the textarea must be shooed in the screen to the client to verify if he want to change anything.. my problem is when I create the textarea with break lignes the text is saved correctly but it cannot be shown on the screen to the client. I found a solution by using :

content.replace(/(?:\r\n|\r|\n)/g, '/
');  

but the problem is this solution working with google but in Firefox it dosen't work ..

Can anyone help me ??

<textarea id="aide-text-content"></textarea>


($('#aide_content_text textarea').val().length != 0 && $('#aide_content_text textarea').val().length != null)
                {
                    content = $('#aide_content_text textarea').val();
                    content = content.replace(/(?:\r\n|\r|\n)/g, '                                                                                                \

You can use white-space: pre or white-space: pre-wrap to break newlines:

 const myText = 'Hello World!\\n\\nLet\\'s get some\\nLINEBREAKS\\nin here'; document.getElementById('container').textContent = myText;
 #container { white-space: pre; }
 <div id="container"></div>

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