문제

I have this very simple br2nl function that I use to take a string and stick it in a textarea. For some reason it's cropping some of the characters off of the ends of some of the lines. Here's my example: http://jsfiddle.net/byZnE/

In this example you will see that the "." (period) is being removed from the sentence in the textarea ("Test about information can go here."). Why is this happening and what can I change in my function to stop it?

도움이 되었습니까?

해결책

This line in your code is problematic:

return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, breakTag);

What you do here is replacing both the symbol before line terminators, if it's not '>', and line terminator itself.

It's really easy to fix, though: just change it to...

return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag);

And, in my opinion, str + '' is redundant here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top