Insert line breaks in text specified in javascript

Doing a partial exchange of texts (reviews fade in / out) using JavaScript and want to insert the equivalent in quotation marks <br/>so that the author of the quote is on the next line. In the code below, I tried following the instructions in JavaScript: how to add line breaks to the HTML text area? but don’t know how to insert /\n\r?/gto make it work.

<script type="text/javascript">
    var text = document.forms[0].txt.value;
    text = text.replace(/\n\r?/g, '<br />');
</script>

<script type="text/javascript">

    window.testimonials = [
        '"This was a great experience" /\n\r?/g - Max Cameron, ThinkTank',
        '"This was a great experience" /\n\r?/g - Max Cameron, ThinkTank',
        "source code"
    ];
</script>

Is there any way to get it to move to the next line? Thank!

+3
source share
2 answers

you are doing something really strange here. why do you insert "regex" in your variables?

fiddle:
http://jsfiddle.net/4Fheu/

:

<script type="text/javascript">
    var text = window.testimonial; // or maybe: document.forms[0].txt.value;
    text = text.replace(/\n\r?/g, '<br />');
    alert(text);
</script>

<script type="text/javascript">

    window.testimonials = [
        '"This was a great experience" \n - Max Cameron, ThinkTank',
        '"This was a great experience" \n - Max Cameron, ThinkTank',
        "source code"
    ];
</script>

/\n\r?/ - , : ' ', 0 1 ' '.

'/\n\r?/' - , :

/
/

+3

, :

window.testimonials = [
'"This was a great experience" /\n\r?/g - Max Cameron, ThinkTank'.replace(/(\n\r?)|(,)/g, '<br />');,
'"This was a great experience" /\n\r?/g - Max Cameron, ThinkTank'.replace(/(\n\r?)|(,)/g, '<br />');,
"source code"];
0

All Articles