PerformanceElementTiming: id property

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính chỉ đọc id của giao diện PerformanceElementTiming trả về id của phần tử liên kết.

Giá trị

Một chuỗi.

Ví dụ

Sử dụng id

Trong ví dụ này, một phần tử <img> đang được quan sát bằng cách thêm thuộc tính elementtiming. Một PerformanceObserver được đăng ký để lấy tất cả các mục hiệu suất loại "element" và cờ buffered được dùng để truy cập dữ liệu từ trước khi trình quan sát được tạo. Nó sẽ ghi myImage ra console, đây là id của phần tử hình ảnh.

html
<img
  src="image.jpg"
  alt="a nice image"
  elementtiming="big-image"
  id="myImage" />
js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.identifier === "big-image") {
      console.log(entry.id);
    }
  });
});
observer.observe({ type: "element", buffered: true });

Thông số kỹ thuật

Thông số kỹ thuật
Element Timing API
# dom-performanceelementtiming-id

Tương thích trình duyệt