JavaScript Newline Character

后端 未结 4 1470
灰色年华
灰色年华 2020-12-29 04:10

From this question, this ...

lines = foo.value.split(/\\r\\n|\\r|\\n/);

is one way to split a string, but how do I join it back with newlin

4条回答
  •  旧巷少年郎
    2020-12-29 04:22

    If you want to join using newline characters, just do:

    lines.join("\r\n");
    

    But if you want to display on the HTML page, you'd want to wrap each line in

    tags:

    html = "

    " + lines.join("

    ") + "

    ";

提交回复
热议问题