开发者

Handling line-breaks across XML/HTML/JQuery

I'm loading an XML file with ajax, dynamically writing/reading values to/from HTML fo开发者_如何学运维rm textareas using jQuery, and then saving back to an XML file by passing it to a PHP-write function on a form submit.

What I'm looking for is a consistent way to handle line-breaks and paragraphs across HTML/jQuery/XML- Something where users would see actual line-breaks, not code, in html and form fields.

Up until now I've been using <br/> tags in CData fields in XML, but these show up in form fields, and jQuery is making a mess of my CData writes.

Any good ideas? Thanks-


If you use actual return characters in the text, then in order to make them show up when displaying as HTML, you could set the css property white-space:pre or white-space:pre-line.


unless i misunderstand the question, php has the built-in functions. nl2br($string); and br2nl($string); you could save the data with nl2br and then load it normally everywhere except the text areas. load to the text area using br2nl($string);


You could use some regex to switch out the <br /> for \n and \r when writing to the form fields.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜