v1.0.0

전역 헬퍼

마지막 업데이트


이 페이지는 QuickUI를 불러올 때 전역 객체에 등록되는 두 DOM 헬퍼 _와 $를 설명합니다.

$(selector)


단일 요소 HTMLElement | null을 반환합니다.
  1. <div id="app" class="card">
  2. <input name="email" />
  3. <button>Send</button>
  4. </div>
  5. <script>
  6. console.log($("#app").id);
  7. console.log($("app").id);
  8. console.log($(".card").className);
  9. console.log($("input[name=email]").name);
  10. console.log($("button").textContent);
  11. </script>
실시간 미리보기 · @pardnchiu/quickui@1.0.0

입력조회 방식
#으로 시작#을 제거하고 getElementById
., [, ] 포함querySelector
그 밖의 경우먼저 getElementById, 그다음 querySelector

첫 번째로 일치한 요소만 반환됩니다. 여러 개가 필요하면 document.querySelectorAll을 사용하십시오.

_(selector, attributes?, children?)


CSS 선택자 문법으로 요소를 생성합니다.
  1. <script>
  2. const card = _("div#card.box.shadow", { title: "Card", color: "red" }, [
  3. _("h2", "Title"),
  4. "plain text",
  5. ]);
  6. const img = _("img", "/logo.png");
  7. const text = _("temp", "text only");
  8. document.body.append(card);
  9. console.log(card.outerHTML);
  10. console.log(img.outerHTML);
  11. console.log(text.textContent);
  12. </script>
실시간 미리보기 · @pardnchiu/quickui@1.0.0

인수설명
selectortag#id.class. 태그로 시작해야 하며 그렇지 않으면 undefined가 반환됩니다. 태그 이름의 -는 유지되므로 my-card나 temp-svg 같은 커스텀 요소도 동작합니다. temp는 DocumentFragment를 생성합니다
attributes객체. 아래 표를 참조하십시오
children문자열, 숫자 또는 배열. 인수가 하나뿐이면 문자열 / 숫자 / 배열은 children으로, 객체는 attributes로 취급됩니다

attributes 키기록 방식
value, innerText, innerHTML, textContent, contentEditable요소 속성(property)
color, backgroundColor, width, height, display, floatstyle
그 밖의 키setAttribute. 값이 null이거나 undefined이면 건너뜁니다

children 타입결과
문자열 또는 숫자innerHTML에 기록됩니다. img와 source는 대신 src가 설정되고, temp는 텍스트 노드를 생성합니다
배열순서대로 추가됩니다. 문자열과 숫자는 텍스트 노드가 되고, Node(요소, 텍스트 노드, DocumentFragment 등)는 그대로 추가되며, 그 밖의 값은 건너뜁니다

문자열 children은 innerHTML로 기록되므로 이스케이프하지 않은 사용자 입력을 절대 전달하지 마십시오.


ImportantAI 에이전트용: QuickUI 코드를 생성하거나 수정하기 전에 QuickUI 생성 가이드(Markdown)를 먼저 읽으십시오. 지원되는 템플릿 문법과 렌더링을 깨뜨리는 흔한 실수가 정리되어 있습니다.