简体   繁体   中英

Html not rendering javascript breaklines as intended

I have a json file which contains some texts, and some of these texts could have some breaklines

"surchargeNoteText":"Please note \r \n that pre-payments will take up to 2 business \r \n days to be allocated to your reservation",

I tried to use \\r and/or \\n and the result was this 在此处输入图片说明

So, the funny thing is that when inspecting the html, the output is right, with 2 break lines.

在此处输入图片说明

So, any tips here ?

Add below CSS will resolve your issue. Thanks

p.jss98 {
   white-space: pre-wrap;
}

Use the <pre> tag to keep the text formatted as you wish

 <pre> I am inside a pre Tag! <pre> 

在HTML中,您需要添加<br />来换行。

"surchargeNoteText":"Please note <br /> that pre-payments will take up to 2 business <br /> days to be allocated to your reservation",

Use &nbsp; instead of \\r and <br/> instead of \\n . In HTML, \\r and \\n doesn't works.

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