<template>: ì½í ì¸ í í릿 ìì
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 11ìâ©.
* Some parts of this feature may have varying levels of support.
HTML <template> ììë íì´ì§ë¥¼ ë¶ë¬ì¨ ìê° ì¦ì ê·¸ë ¤ì§ì§ë ìì§ë§, ì´í JavaScript를 ì¬ì©í´ ì¸ì¤í´ì¤ë¥¼ ìì±í ì ìë HTML ì½ë를 ë´ì ë°©ë²ì ì ê³µí©ëë¤.
í
í릿ì ì½í
ì¸ ì¡°ê°ì ëì¤ì ì¬ì©í기 ìí´ ë´ìëë 컨í
ì´ëë¡ ìê°íì¸ì. íì´ì§ë¥¼ ë¶ë¬ì¤ë ëì 구문 ë¶ìê¸°ê° <template> ììì ì½í
ì¸ ë ì½ê¸°ë íì§ë§, ì´ë ì í¨ì±ì ê²ì¦í기 ìí¨ì´ë©° ë ëë§ í기 ìí¨ì ìëëë¤.
| ì½í ì¸ ì¹´í ê³ ë¦¬ | ë©íë°ì´í° ì½í ì¸ , íë¡ì° ì½í ì¸ , 구문 ì½í ì¸ , ì¤í¬ë¦½í¸ ì§ì ìì. |
|---|---|
| ê°ë¥í ì½í ì¸ | ì í ìì. |
| íê·¸ ìëµ | ë¶ê°ë¥, ììê³¼ ëì í그를 ì¶ê°íë ê²ì íìì ëë¤. |
| ê°ë¥í ë¶ëª¨ ìì |
ë©íë°ì´í° ì½í
ì¸ , 구문 ì½í
ì¸ , ëë ì¤í¬ë¦½í¸ ì§ì ìì를 íì©íë 모ë
ìì. ëí, span í¹ì±ì´ ìë
<colgroup> ììë ê°ë¥.
|
| ê°ë¥í ARIA ìí | ìì |
| DOM ì¸í°íì´ì¤ | HTMLTemplateElement |
í¹ì±
ì´ ììë ì ì í¹ì±ë§ í¬í¨í©ëë¤.
ë¤ë§, HTMLTemplateElementë ì½ê¸° ì ì© content ìì±ì ê°ì§ëë¤. contentë í
íë¦¿ì´ ë´ê³ ìë DOM íì í¸ë¦¬ë¥¼ ëíë´ë DocumentFragmentì
ëë¤.
ìì
ì°ì ìì ì HTMLë¶í° ë³´ê² ìµëë¤.
<table id="producttable">
<thead>
<tr>
<td>UPC_Code</td>
<td>Product_Name</td>
</tr>
</thead>
<tbody>
<!-- ì¡´ì¬íë ë°ì´í°ë ì íì ì¼ë¡ ì¬ê¸°ì í¬í¨ë©ëë¤ -->
</tbody>
</table>
<template id="productrow">
<tr>
<td class="record"></td>
<td></td>
</tr>
</template>
먼ì , ëì¤ì JavaScript ì½ë를 ì¬ì©í´ 컨í ì¸ ë¥¼ ì½ì í í ì´ë¸ì´ ììµëë¤. ê·¸ ë¤ì í ì´ë¸ì ì´ì íííë HTML ì¡°ê°ì 구조를 ì¤ëª íë í íë¦¿ì´ ìµëë¤.
ì´ì í ì´ë¸ì´ ìì±ëìê³ í íë¦¿ì´ ì ìëìì¼ë¯ë¡, JavaScript 를 ì¬ì©í´ í í릿ì ì¬ì©í´ 구ì±ë ì´ì 기ë°ì¼ë¡ ê° ì´ì í ì´ë¸ë¡ ì½ì í©ëë¤.
// í
í릿 ì리먼í¸ì 컨í
ì¸ ì¡´ì¬ ì 무를 íµí´
// ë¸ë¼ì°ì ê° HTML í
í릿 ì리먼í¸ë¥¼ ì§ìíëì§ íì¸í©ëë¤
if ("content" in document.createElement("template")) {
// 기존 HTML tbody ì í
í릿 ì´ë¡ í
ì´ë¸ì ì¸ì¤í´ì¤íí©ëë¤
var t = document.querySelector("#productrow");
// ìë¡ì´ ì´ì ë³µì íê³ í
ì´ë¸ì ì½ì
í©ëë¤
var tb = document.querySelector("tbody");
var clone = document.importNode(t.content, true);
td = clone.querySelectorAll("td");
td[0].textContent = "1235646565";
td[1].textContent = "Stuff";
tb.appendChild(clone);
// ìë¡ì´ ì´ì ë³µì íê³ í
ì´ë¸ì ì½ì
í©ëë¤
var clone2 = document.importNode(t.content, true);
td = clone2.querySelectorAll("td");
td[0].textContent = "0384928528";
td[1].textContent = "Acme Kidney Beans 2";
tb.appendChild(clone2);
} else {
// HTML í
í릿 ì리먼í¸ë¥¼ ì§ìíì§ ìì¼ë¯ë¡
// í
ì´ë¸ì ì´ì ì¶ê°íë ë¤ë¥¸ ë°©ë²ì ì°¾ìµëë¤.
}
ê²°ê³¼ë JavaScript 를 íµí´ ì¶ê°ë ë ê°ì ìë¡ì´ ì´ì í¬í¨íë 기존 HTML í ì´ë¸ì ëë¤.
ëª ì¸
| Specification |
|---|
| HTML > # the-template-element > |