乐者为王

Do one thing, and do it well.

JSP中怎样输出\r\n到textarea中

测试代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%
    String str = "first line\r\nsecond line";
%>

<body>
    <textarea id="editor" name="editor"></textarea>;
</body>

<script type="text/javascript">
<!–-
    var editor = document.getElementById('editor');
    editor.value = '<%= str.replaceAll("\r\n", "\\\\r\\\\n") %>';
//-–>
</script>

Comments