- Mastering Angular Components
- Gion Kunz
- 211字
- 2021-07-23 17:23:38
Template elements
Template elements allow you to define regions within your HTML, which will not be rendered by the browser. You can then instantiate these document fragments with JavaScript and then place the resulting DOM within your document.
While the browser is actually parsing the template content, it only does so in order to validate the HTML. Any immediate actions that the parser would usually execute will not be taken. Within the content of template elements, images will not be loaded and scripts won't be executed. Only after a template is instantiated will the parser take the necessary actions, as follows:
<body>
<template id="template">
<h1>This is a template!</h1>
</template>
</body>
This simple HTML example of a template element won't display the heading on your page. As the heading is inside a template element, we first need to instantiate the template and add the resulting DOM into our document:
var template = document.querySelector('#template');
var instance = document.importNode(template.content, true);
document.body.appendChild(instance);
Using these three lines of JavaScript, we can instantiate the template and append it into our document.
- 智慧城市:大數據、互聯網時代的城市治理(第4版)
- 微商之道
- 解析QUIC/HTTP3:未來互聯網的基石
- 物聯網安全(原書第2版)
- 光網絡評估及案例分析
- Building Django 2.0 Web Applications
- 城域網與廣域網(第2版)
- 網絡環境中基于用戶視角的信息質量評價研究
- 高級網絡技術
- Getting Started with nopCommerce
- 設備監控技術詳解
- 智能物聯網:區塊鏈與霧計算融合應用詳解
- Hands-On Reactive Programming in Spring 5
- 通信系統實戰筆記:無處不在的信號處理
- Hands-On Microservices:Monitoring and Testing