更新时间:2023-02-19 16:58:45
你可以用 script
元素(由我加粗):
You can do this with the script
element (bolded by me):
脚本
元素允许作者包含动态脚本和数据块在他们的文件中。
The
script
element allows authors to include dynamic script and data blocks in their documents.
示例:
<script type="text/plain">
This content has the media type plain/text, so characters reserved in HTML have no special meaning here: <div> ← this will be displayed.
</script>
(请注意脚本的允许内容
元素是限制,例如你不能 < / script>
作为文本内容(它将关闭脚本
元素)。)
(Note that the allowed content of the script
element is restricted, e.g. you can’t have </script>
as text content (it would close the script
element).)
通常, script
元素在浏览器的CSS中默认为 display:none
,所以你需要在CSS中覆盖它,例如:
Typically, script
elements have display:none
by default in browser’s CSS, so you’d need to overwrite that in your CSS, e.g.:
script[type="text/plain"] {display:block;}