I obtain a string in the background and output it to the
tag in the foreground, but there is a newline character 'n' in the string, and I want to output the newline effect in the same way. How should I deal with this string? I replaced 'n' with
but it still didn't work, and it was output as is.
thank you all
There are two ways, one is to set
white-space: pre;
, the white space will be retained by the browser. Or use, the pre element can define pre-formatted text. Text enclosed in a pre element usually preserves whitespace and newlines.
Isn’t the
line break character
n
?If you are in this situation, change it to
According to your description, you should need the
pre
tag.In js, you can use
. innerHTML = 'It
to output html; if it is jQuery, useworks'
$.fn.html('It
!works')
==== I thought it was PHP output
Use the htmlentities function to output the replaced content!
This is possible. It’s best for the questioner to post the code to know the reason
n
valid in precan be passed in p via
replace