How to replace \n with
in JavaScript?

后端 未结 10 2103
面向向阳花
面向向阳花 2020-12-31 00:44

I have a textarea where I insert \\n when user presses enter. Code from this textarea is sent to a WCF service via jQuery.ajax(). I cannot save

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 01:12

    Like said in comments and other answer, it's better to do it on server side.

    However if you want to know how to do it on clientside this is one easy fix:

    textareaContent.replace(/\\n/g, "
    ");

    Where textareaContent is the variable with the data in the textarea.

    Edit: Changed so that it replaces globally and not only first match.

提交回复
热议问题