最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Displaying <textarea> value as HTML - Stack Overflow

programmeradmin2浏览0评论

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 wondering if there is a standard solution to that either on server side (C#) or client side (javascript)

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 wondering if there is a standard solution to that either on server side (C#) or client side (javascript)

Share Improve this question asked Dec 28, 2010 at 21:38 AndreyAndrey 21.3k28 gold badges117 silver badges180 bronze badges 1
  • 2 You can try to style p tag with style="white-space:pre;" – dev-null-dweller Commented Dec 28, 2010 at 21:41
Add a ment  | 

3 Answers 3

Reset to default 4

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)

  1. 暂无评论