展示 作为文本区域中的字符
Display 
 as Character in textarea
在我的 html 页面中,我有一个 textarea 标签和其中的一些文本。稍后我会处理文本。
<html>
<body>
<textarea name="" id="" cols="30" rows="10">
test
test
</textarea>
</body>
</html>
但是在输出html页'
' (添加 space 以避免字符不可见)被替换为换行符。我想将这些字符视为 character。基本上我想避免被解析。
我做了很多研究
查看了 html escape characters 并没有找到任何东西。
我还看了一个 SO 问题 here,我想做完全相反的事情。
你可以看看jsfiddle here
有没有办法转义这个字符。
提前致谢。
textarea
是一个 escapable raw text element, so any sequence of characters inside it that starts with "&
" (ampersand) and that ends with a semicolon gets parsed as a character reference.
因此,为了防止问题中 test
test
代码片段中的 

被解析为换行符的字符引用,只需将“&
”替换为 &
:
test&#xA;test
<html>
<body>
<textarea name="" id="" cols="30" rows="10">
test&#xa;test
</textarea>
</body>
</html>
在我的 html 页面中,我有一个 textarea 标签和其中的一些文本。稍后我会处理文本。
<html>
<body>
<textarea name="" id="" cols="30" rows="10">
test
test
</textarea>
</body>
</html>
但是在输出html页' ' (添加 space 以避免字符不可见)被替换为换行符。我想将这些字符视为 character。基本上我想避免被解析。
我做了很多研究 查看了 html escape characters 并没有找到任何东西。
我还看了一个 SO 问题 here,我想做完全相反的事情。
你可以看看jsfiddle here
有没有办法转义这个字符。
提前致谢。
textarea
是一个 escapable raw text element, so any sequence of characters inside it that starts with "&
" (ampersand) and that ends with a semicolon gets parsed as a character reference.
因此,为了防止问题中 test
test
代码片段中的 

被解析为换行符的字符引用,只需将“&
”替换为 &
:
test&#xA;test
<html>
<body>
<textarea name="" id="" cols="30" rows="10">
test&#xa;test
</textarea>
</body>
</html>