# 제품을 바꿔도 비교 기준 유지

Apple · 제품 비교 · 2026년 11월 20일 확인

## 원본에서 본 동작

첫 열의 모델을 바꾸자 비교 제목과 주소의 modelList가 바뀌고 옆에 둔 두 모델은 유지됐습니다. 각 모델의 정보는 같은 사양 순서로 나열됩니다. [Apple 한국 iPhone 모델 비교](https://www.apple.com/kr/iphone/compare/)

## 적용할 때

제품, 요금제, 납품 견적처럼 같은 기준으로 비교할 수 있는 후보에 씁니다. 물리량의 단위와 측정 조건을 우선 맞춥니다.

예제는 작업등 두 모델과 네 가지 사양을 보여줍니다. 열마다 독립적인 선택기를 두고 행 및 열 제목에 의미를 부여합니다. 웹 주소에는 두 제품의 ID와 비교 조건을 기록해 같은 표를 다시 열 수 있게 합니다.

‘차이·미확인 항목만 보기’는 이번 예제에 추가한 기능입니다. 값이 확인됐고 서로 같을 때만 행을 숨깁니다. 양쪽에 정보가 없어도 해당 행과 ‘정보 미제공’ 표시가 남습니다.

## 확인하는 방법

한쪽 모델을 바꿔 반대 열과 행의 기준이 유지되는지 봅니다. 차이만 보기에서 같은 제품을 고르고, 사용 시간이 누락된 제품도 골라봅니다.

## 그대로 보낼 요청

> 납품 후보 두 곳을 행 제목이 고정된 비교표로 만들어줘. 한쪽 후보만 교체할 수 있게 하고, 견적이 없는 값은 ‘미제공’으로 표시해줘. 서로 다른 항목만 모아서 볼 수 있어야 해.

[실행 데모](../examples/spec-compare/index.html) · [단일 HTML 저장](../downloads/spec-compare.html) · [사례 목록에서 보기](../tools/references.html#spec-compare)

## 실행 코드

아래 HTML 전체를 파일 하나로 저장해 브라우저에서 열 수 있습니다. 화면과 조작에 필요한 자료가 모두 들어 있습니다.

<!-- standalone-example -->

```html
<!doctype html>
<html lang="ko"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>작업등 비교 · UI Motion Lab</title>
<style>:root{color-scheme:light;--paper:#f5f3ec;--ink:#262820;--line:#c7c6b7;--accent:#98402b}
*{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font:15px/1.55 Arial,'Apple SD Gothic Neo','Malgun Gothic',sans-serif;overflow-wrap:anywhere}
main{width:min(810px,calc(100% - 36px));margin:clamp(20px,5vh,58px) auto}
main h1{margin:0;font-size:clamp(28px,4.1vw,47px);font-weight:700;line-height:1.15;letter-spacing:-.065em}
main>p{color:#56594e;margin:8px 0 22px;line-height:1.55}.panel{padding:clamp(15px,2.7vw,28px);background:#fffdf6;border:1px solid var(--line);border-radius:2px}
button,select,input,textarea{font:inherit}button,select{min-height:40px}button{cursor:pointer}button:disabled{cursor:default;opacity:.45}
button,select{background:#faf9f0;color:inherit;border:1px solid #a6a798;border-radius:3px;padding:5px 12px}
:focus-visible{outline:3px solid #945030;outline-offset:3px}button:enabled:hover,select:hover{border-color:var(--ink)}
[hidden]{display:none!important}.lab-embedded [data-lab-shell]{display:none!important}.lab-embedded main{margin:clamp(12px,2vh,25px) auto}
figure,fieldset{margin:0}p:last-child{margin-bottom:0}fieldset{min-width:0}
@media(max-width:460px){main{width:calc(100% - 24px);margin:16px auto}main>p{font-size:13px;margin:5px 0 14px}main h1{font-size:26px}.panel{padding:13px}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}
.lab-reduce *,.lab-reduce *::before,.lab-reduce *::after{animation-duration:.01ms!important;transition-duration:.01ms!important;scroll-behavior:auto!important}
.panel{background:#f7f6ee}.picks{display:grid;grid-template-columns:1fr 1fr;gap:clamp(10px,2vw,20px)}
.picks>label{display:block;color:#575c51;font-size:12px}.picks select{display:block;width:100%;margin-top:4px;font-weight:700}
.lamp-art{--enamel:#7f4031;position:relative;display:block;overflow:hidden;height:clamp(81px,15vw,125px);margin-top:4px;background:radial-gradient(ellipse at 50% 88%,#aaab92 0,transparent 25%),linear-gradient(120deg,#e1e2cf,#d2d2bc)}
.lamp-art i{position:absolute;left:50%;height:48%;width:5px;bottom:15%;background:var(--enamel);transform:rotate(12deg);transform-origin:bottom}
.lamp-art b{position:absolute;left:calc(50% - 18px);top:19%;height:24%;width:50px;background:linear-gradient(100deg,#0002,var(--enamel));background-color:var(--enamel);border-radius:50px 50px 4px 4px;transform:rotate(12deg)}
.lamp-art em{position:absolute;bottom:12%;left:calc(50% - 22px);height:6px;width:44px;background:var(--enamel);border-radius:45%}
.lamp-art[data-lamp=field]{--enamel:#3e5949;background:radial-gradient(ellipse at 50% 88%,#a9ac98,transparent 25%),#dedfce}.lamp-art[data-lamp=field] i{transform:none;width:9px}.lamp-art[data-lamp=field] b{transform:none;left:calc(50% - 18px);width:44px;height:36%;border-radius:22px 22px 6px 6px}
.lamp-art[data-lamp=atelier]{--enamel:#393b37}.lamp-art[data-lamp=atelier] i{transform:rotate(-23deg)}.lamp-art[data-lamp=atelier] b{left:calc(50% - 40px);transform:rotate(-22deg);height:17%;width:53px;border-radius:3px}
.table-head{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;margin:13px 0 4px}.difference{display:flex;align-items:center;gap:4px;font-size:13px}.difference input{accent-color:#3e5949}#summary,caption{font-size:11px;color:#555b50}
table{width:100%;border-collapse:collapse;font-variant-numeric:tabular-nums;font-size:14px}caption{caption-side:bottom;text-align:left;margin-top:8px}th,td{text-align:left;border-bottom:1px solid #c7c8b7;padding:5px 8px}thead th{background:#39483c;color:#fffdf1}tbody th{font-weight:500}tbody tr:has(td+td){background:#f3f2e7}
</style>
<script>
const viewOptions=new URLSearchParams(location.search);
document.documentElement.classList.toggle('lab-embedded',viewOptions.get('embed')==='1');
document.documentElement.classList.toggle('lab-reduce',viewOptions.get('reduce')==='1');
</script>
</head>
<body class="lab-example">
<main><h1>작업등 비교</h1><p>각 열에서 작업등을 고르고 무게, 사용 시간, 전원, 밝기를 비교하세요.</p>
<section class="panel" aria-label="제품 비교">
 <div class="picks">
 <label>첫 번째 작업등<span class="lamp-art" aria-hidden="true"><i></i><b></b><em></em></span><select id="left"></select></label>
 <label>두 번째 작업등<span class="lamp-art" aria-hidden="true"><i></i><b></b><em></em></span><select id="right"></select></label></div>
 <div class="table-head"><label class="difference"><input type="checkbox" id="diff"> 차이·미확인 항목만 보기</label><span id="summary" role="status"></span></div>
 <table><caption>작업등별 사양 · 예시 제품</caption><thead><tr><th scope="col">사양</th><th id="name-left" scope="col"></th><th id="name-right" scope="col"></th></tr></thead>
 <tbody id="specs"></tbody></table>
</section>
</main>
<script>

const lamps = [
  { id: "dock", name: "도크", weight: "480 g", time: "6시간", power: "USB-C", levels: "3단계" },
  { id: "field", name: "필드", weight: "320 g", time: "9시간", power: "USB-C", levels: "3단계" },
  { id: "atelier", name: "아틀리에", weight: "620 g", time: null, power: "AC 전원", levels: "5단계" }
];
const fields = [["무게","weight"],["사용 시간","time"],["전원","power"],["밝기","levels"]];
const selectors = [document.querySelector("#left"), document.querySelector("#right")];
const diff = document.querySelector("#diff");
function render() {
  const [first, second] = selectors.map(select => lamps.find(lamp => lamp.id === select.value));
  selectors.forEach((s,i)=>{s.parentElement.querySelector(".lamp-art").dataset.lamp=[first,second][i].id});
  document.querySelector("#name-left").textContent = first.name;
  document.querySelector("#name-right").textContent = second.name;
  const tbody = document.querySelector("#specs");
  tbody.replaceChildren();
  for (const [label, key] of fields) {
    if (diff.checked && first[key] != null && first[key] === second[key]) continue;
    const row = tbody.insertRow();
    const heading = document.createElement("th");
    heading.scope = "row";
    heading.textContent = label;
    row.append(heading);
    for (const product of [first, second]) row.insertCell().textContent = product[key] ?? "정보 미제공";
  }
  document.querySelector("#summary").textContent = tbody.rows.length
    ? "비교 항목 " + tbody.rows.length + "개" : "두 제품의 표시된 사양이 모두 같습니다.";
}
function restore() {
  const params = new URL(location.href).searchParams;
  selectors.forEach((select, index) => {
    const id = params.get(select.id);
    select.value = lamps.some(lamp => lamp.id === id) ? id : lamps[index].id;
  });
  diff.checked = params.get("different") === "1";
  render();
}
function change() {
  render();
  if (!/^https?:$/.test(location.protocol)) return;
  const url = new URL(location.href);
  selectors.forEach(select => url.searchParams.set(select.id, select.value));
  if (diff.checked) url.searchParams.set("different", "1");
  else url.searchParams.delete("different");
  if (url.href !== location.href) history.pushState(null, "", url);
}
selectors.forEach(select => {
  lamps.forEach(lamp => select.add(new Option(lamp.name, lamp.id)));
  select.addEventListener("change", change);
});
diff.addEventListener("change", change);
window.addEventListener("popstate", restore);
restore();
</script>
</body></html>
```
