HTML newline using fromCharCode is not working

前端 未结 2 948
野性不改
野性不改 2021-01-26 09:39

I am using String.fromCharCode to add new line (or) carriage return to my html text.

It is like,

\"Ant the other line here...\" + String.fro         


        
相关标签:
2条回答
  • 2021-01-26 10:00

    If you want a line break in HTML you need to supply <br> entity instead of a line break (your String.fromCharCode(13) code) since HTML interprets line breaks as usual spaces in text.

    0 讨论(0)
  • 2021-01-26 10:21

    The reason that a newline character is not forcing a new line, is that in HTML a newline character doesnt do anything and is ignored.

    In order to force text onto a new line, you will need to add the appropriate HTML tag, such as <BR> or put your text inside paragraphs <p>.

    See the updated fiddle.

    0 讨论(0)
提交回复
热议问题