Baseline Widely available *
HTML <template>
ììë íì´ì§ë¥¼ ë¶ë¬ì¨ ìê° ì¦ì ê·¸ë ¤ì§ì§ë ìì§ë§, ì´í JavaScript를 ì¬ì©í´ ì¸ì¤í´ì¤ë¥¼ ìì±í ì ìë HTML ì½ë를 ë´ì ë°©ë²ì ì ê³µí©ëë¤.
í
í릿ì ì½í
ì¸ ì¡°ê°ì ëì¤ì ì¬ì©í기 ìí´ ë´ìëë 컨í
ì´ëë¡ ìê°íì¸ì. íì´ì§ë¥¼ ë¶ë¬ì¤ë ëì 구문 ë¶ìê¸°ê° <template>
ììì ì½í
ì¸ ë ì½ê¸°ë íì§ë§, ì´ë ì í¨ì±ì ê²ì¦í기 ìí¨ì´ë©° ë ëë§ í기 ìí¨ì ìëëë¤.
ì´ ììë ì ì í¹ì±ë§ í¬í¨í©ëë¤.
ë¤ë§, 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 í ì´ë¸ì ëë¤.
table {
background: #000;
}
table td {
background: #fff;
}
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4