开发者

Displaying <textarea> value as HTML

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜