Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #3069

unique-id

Skill này làm gì

Skill này kiểm tra mỗi id trên trang web chỉ được dùng một lần. Skill dành cho lập trình viên thấy nhãn bị hỏng hoặc script chọn nhầm phần tử.

Khi nào nên dùng

  • ✓Khi một trang có cùng một id trên nhiều hơn một phần tử.
  • ✓Khi nhãn biểu mẫu hoặc liên kết ARIA không kết nối với các ô nhập.
  • ✓Khi một thư viện component có thể đã tạo ra id trùng.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/unique-id/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/unique-id/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Nhãn biểu mẫu của tôi ngừng hoạt động khi tôi dùng component này hai lần trên một trang. Bạn có thể kiểm tra id trùng không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent quét trang để tìm các giá trị id bị lặp. Sau đó agent gán cho mỗi phần tử một id duy nhất và cập nhật các nhãn, tham chiếu ARIA và script đang dùng chúng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Ensure all IDs are unique

Duplicate IDs break form accessibility (labels don't connect), ARIA relationships fail, and JavaScript getElementById returns wrong elements—causing silent bugs.

Quick Reference

  • Each ID must appear only once per HTML document
  • Use classes for styling, IDs for unique anchors/references
  • Check for duplicates introduced by component libraries
  • Duplicate IDs break form labels, ARIA, and getElementById

Check

Scan this HTML document to ensure all ID attributes are unique across the entire page and properly reference related elements.

Fix

Remove duplicate ID values, ensure each ID is used only once per page, and update any references like labels, ARIA attributes, or JavaScript selectors.

Explain

Explain why unique IDs are essential for HTML validity, accessibility (form labels, ARIA), JavaScript functionality, and CSS styling.

Code Review

Review templates, server-rendered HTML, and shared components that output markup related to Ensure all IDs are unique. Flag exact elements, attributes, and routes where the rendered HTML violates the rule.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/html/unique-id

Câu hỏi thường gặp

Vì sao id trùng lại quan trọng?

Chúng làm hỏng nhãn biểu mẫu, liên kết trợ năng và các lệnh getElementById, có thể gây lỗi âm thầm.

Có nên dùng id để tạo kiểu không?

Skill khuyên dùng class để tạo kiểu, và chỉ dùng id cho neo hoặc tham chiếu duy nhất.

Thư viện component có thể gây ra việc này không?

Có. Skill nói rằng các thư viện component có thể đưa vào id trùng.

Chi tiết

Mô tả gốc của tác giả

Use when reviewing templates, rendered HTML, or shared components related to Ensure all IDs are unique. Validate the final browser-facing markup, not just the source framework abstraction.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3069
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự