我一直在使用这个漂亮的技巧来存储元数据块,无论是JSON还是HTML片段:
<script type="text/html">
<p>This gets something done to it later.</p>
</script>
<script type="application/json">
{"name":"Niet","species":"Absol"}
</script>
然后,JavaScript会获取这些标记并以某种方式使用它们的内容。
这很有效。我只有一个问题......
<script type="text/html">
<p>This is a template for something used in many places.</p>
<p>Rather than having, say, a hundred copies of basically the same thing,
this lets me define the HTML once and then re-use it as needed,
while allowing for easy editing because it doesn't need mass escaping.</p>
<p>However, what if I want a template that contains a template?</p>
<script type="text/html">
<p>Nested scripts?</p>
<p>That's not gonna work.</p>
</script>
</script>
那又怎么样?是否还有另一个标签,也许是我还没有听说过的新HTML5功能,这让我可以用这种方式定义模板和其他数据?