HTML Display line breaks within textarea

后端 未结 3 893
逝去的感伤
逝去的感伤 2020-12-16 09:57

I have asked this question now several ways, but still have not gotten an answer.

When you capture asci text in a textarea that includes line breaks, it seems to ins

相关标签:
3条回答
  • 2020-12-16 10:37

    I am not sure to anderstand your question.

    If you want to write this in your <textarea/>

    first line
    second line
    

    You should write this:

    <html>
        <head>
            <title></title>
        </head>
        <body>
            <textarea rows="4" cols="40">
    first line
    second line
            </textarea>
        </body>
    </html>
    

    In PHP you should write this

    <html>
        <head>
            <title></title>
        </head>
        <body>
            <textarea rows="4" cols="40"><?php echo "first line\r\nsecond line" ?></textarea>
        </body>
    </html>
    

    Make sure that string is between " and not '

    0 讨论(0)
  • 2020-12-16 10:47

    Well if you're doing this through pure HTML, then you can do it one of two ways. Just add lines by pressing enter or using the ASCII characters &#013; &#010;

    jsFiddle

    0 讨论(0)
  • 2020-12-16 10:50

    If you are using javascript you can use the textarea element value Property.

    var tb = document.getElementById("tb");
    
    var newLine = "\r\n";
    
    var text = "Output: " + newLine + "-------------------" + 
                            newLine + "line 1:	" + 
                            newLine + "line 2:	";
    
    tb.value = text;
    //console.log(text);
    <textarea id="tb" rows=5>
    Output: &#13;&#10;-------------
    </textarea>

    Run it on JSFiddle

    0 讨论(0)
提交回复
热议问题