我需要一种方法将<textarea>
(作为文本(放入<textarea>
,然后用</textarea>
关闭文本区域内的文本区域,但这样做会关闭第一个文本区域。它允许代码<textarea>
在文本区域内
<textarea width=100px> <!--Text area to appear on screen-->
<title> Test </title>
<textarea placeholder="Hello, Enter your username:">
</textarea> <!--This bit is supposed to appear inside the text area as text-->
</textarea> <!--End of the textarea-->
我试过使用:
<script>
<!--
document.write(unescape("%3C/textarea%3E"));
//-->
</script>
而不是</textarea>
但它不起作用
将<
替换为其等效的 HTML 实体 - <
:
<textarea width=100px>
<!--Text area to appear on screen-->
<title>Test</title>
<textarea placeholder="Hello, Enter your username:">
</textarea> <!--This bit is supposed to appear inside the text area as text-->
</textarea><!--End of the textarea-->
演示。不要将其与URL编码(%nn
(混淆,因为它们是不同的野兽。
你应该在 html 中转义特殊字符,如 <> & 和 ":
<= <<br>> =>
& = &
" = ">
这看起来像:
<textarea placeholder="Hello, Enter your username:">
</textarea>
</textarea> <!--End of the textarea-->
如果您使用服务器端脚本/程序来渲染 html,几乎所有语言都有 html 转义函数。