开发者

How to get the new line break if there are some in the text area

I have textarea and i want, when i post the form if t开发者_运维技巧here are any new lines in the text area to get them and output the text with them, like the wysiwyg editors does.

What can't you understand

I have form and i want to get te text area value on post SO IF THERE ARE NEW LINES IN THE VALUE OF THE TEXT AREA I WANT WHEN I OUTPUT THE TEXT THAT THE FORM GETED THOSE NEW LINES TO BE DISPLAYED AS ACTUALY NEW LINES LIKE THE WYSIWYG EDITORS>


Line breaks are interpreted as \n.

With javascript you can use regular expression to detect the new line character.

regex:

/\n/

UPDATE:

var newStr = "String with line breaks".replace(/\n/g,"<br />");

this will replace the new line in textarea with <br> tag to make a new line


You can use a regular expression in JavaScript to search for new line character RegExp("\n").

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜