Jquery textarea val() doesnt take new line
I get a textarea with a keyup开发者_Python百科 function attached. When the user type something, I want this text to be rendered inside the blockquote tag. It works, but id doesn't take the newline and spaces. Can you helpe me?
$('#post_body').keyup(function() {
$('blockquote').find('span').text($(this).val());
It does take a newline, however those are usually ignored when rendering HTML. However, you can give that <span>
(or the <blockquote>
) newline rendering to match by setting it's white-sapce
to be the same as a <pre>
element, like this:
blockquote span { white-space: pre; }
//or..
blockquote { white-space: pre; }
You can test it out here.
A raw solution would be to replace all newlines with <br/>;
tag and all spaces with &nbsp;
精彩评论