开发者

Displaying <textarea> value as HTML

开发者 https://www.devze.com 2023-02-01 18:57 出处:网络
I have a form with several textarea elements. User enters data and submits the form. On the next page it shows submitted text as static text - in p tags. Obviously New Line and multiple paces get igno

I have a form with several textarea elements. User enters data and submits the form. On the next page it shows submitted text as static text - in p tags. Obviously New Line and multiple paces get ignored and everything just shows in one line.

I can do some preprocessing like replacing New line characters with "br/" and spaces with  . but I was wonderin开发者_开发技巧g if there is a standard solution to that either on server side (C#) or client side (javascript)


Since the data is preformatted (and this isn't just a matter of presentation), the pre element would be suitable (you will still need to replace <, & and friends with the appropriate entities).


Apply CSS white-space: pre; on the <p> element. This way any whitespace inside the element will be preserved.


Actually, I ended up replacing new line symbol with [br/] and it works very well.

0

精彩评论

暂无评论...
验证码 换一张
取 消