source: http://stackoverflow.com/questions/4912586/explanation-of-script-type-text-template-script
Answer:
Answer:
Those script tags are a common way to implement templating functionality (like in PHP) but on the client side.
By setting the type to "text/template", it's not a script that the browser can understand, and so the browser will simply ignore it. This allows you to put anything in there, which can then be extracted later and used by a templating library to generate HTML snippets.
Backbone doesn't force you to use any particular templating library - there are quite a few out there:Mustache, Haml, Eco, and so on (the one used in the example you linked to is underscore.js). These will use their own syntax for you to write within those script tags.
Obsolete way to implement:
<script id="hello" type="text/template">
Hello world
</script>
<script>
alert($('#hello').html());
</script>
New standard:
<script type = “text/template”> … </script>
is obsolote. Use <template>
tag instead.<template id="hello"> Hello world </template> <script> alert($('#hello').html()); </script>
Refer to: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
댓글
댓글 쓰기