什么字符代表文本区域中的新行 [英] What character represents a new line in a text area
问题描述
我喜欢将输入到文本区的新行转换为[逗号],所以输出可以在一行代表,我的问题...
目前,从谷歌浏览器发送,当我查看该值时,我发现它对新行使用 \r\\\
。如果我替换
\r\\\
我知道它适用于Windows 7上的chrome,但其他平台又如何,其他浏览器会插入哪些变体作为文本区域内的新行?
通过HTML规范,浏览器需要规范用户输入中的换行符LF LF \r\\\
),我不认为任何浏览器都会出错。参考:条款17.13.4 表单内容类型在HTML 4.01规范中。
在HTML5草案中,情况更加复杂,因为它们也处理浏览器内的流程,而不仅仅是发送到提交表单时的服务器端表单处理程序。根据他们(和浏览器的做法), textarea
元素值存在三种变体:
- 由用户输入的原始值,非标准化;它可能包含CR,LF或CR LF对;
- 称为API值的内部值,其中换行符标准化为LF(仅); 根据互联网约定,被归一化为CR LF对。
Just quick one, but want to make sure I'm catching cross platform variations.
I like to convert new lines entered into a text area into a [comma], so that the output can be represented on a single line, my question...
Currently, sending from google chrome, when I view the value, I find it uses \r\n
for new lines. If I replace \r\n
I know it will work for chrome on windows 7, but what about other platforms, are there variations on what other browsers will insert as a new line inside a text area?
By HTML specifications, browsers are required to canonicalize line breaks in user input to CR LF (\r\n
), and I don’t think any browser gets this wrong. Reference: clause 17.13.4 Form content types in the HTML 4.01 spec.
In HTML5 drafts, the situation is more complicated, since they also deal with the processes inside a browser, not just the data that gets sent to a server-side form handler when the form is submitted. According to them (and browser practice), the textarea
element value exists in three variants:
- the raw value as entered by the user, unnormalized; it may contain CR, LF, or CR LF pair;
- the internal value, called "API value", where line breaks are normalized to LF (only);
- the submission value, where line breaks are normalized to CR LF pairs, as per Internet conventions.
这篇关于什么字符代表文本区域中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!