html textarea中的newline字符

发布于 2025-01-18 07:50:23 字数 640 浏览 4 评论 0原文

参考以下问题下的答案 - 什么字符代表文本区域中的新行

尽管在文本区域中输入数据,但文本区域中的换行符应该是 CRLF换行符仅生成 \n,如下面的代码片段所示 -

<textarea id="one" onchange="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)"></textarea>
<button onclick="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)">Read Content</button>
<div id="contentdiv"></div>

对于此处看到的更改行为,文本区域的定义标准是否有参考/更改?

With reference to the answers available under following question -
What character represents a new line in a text area

The newline character in a textarea should be CRLF though entering data in a textarea with newline generates only \n as can be seen in the snippet below -

<textarea id="one" onchange="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)"></textarea>
<button onclick="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)">Read Content</button>
<div id="contentdiv"></div>

Are there references/changes in the defined standards for the textarea with respect to the changed behavior seen here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬﹪忆之殇 2025-01-25 07:50:23

您提供的链接实际上有一个答案。

Textarea元素值存在于三个变体中:

  1. 用户输入的原始值,未正均;它可能包含CR,LF或CR LF对;
  2. 内部值,称为“ API值”,其中
    线路断裂归一化为LF(仅);
  3. 根据互联网约定,提交价值,将线路断裂标准化为CR LF对。

您的情况是2号

The link you've provided actually has an answer.

The textarea element value exists in three variants:

  1. the raw value as entered by the user, unnormalized; it may contain CR, LF, or CR LF pair;
  2. the internal value, called “API value”, where
    line breaks are normalized to LF (only);
  3. the submission value, where line breaks are normalized to CR LF pairs, as per Internet conventions.

Your case is number 2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文