SVGElement: thuộc tính dataset
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
Thuộc tính chỉ đọc dataset của giao diện SVGElement cung cấp quyền đọc/ghi các thuộc tính dữ liệu tùy chỉnh (data-*) trên các phần tử. Nó cung cấp một bản đồ các chuỗi (DOMStringMap) với một mục cho mỗi thuộc tính data-*.
Để biết thêm thông tin về cách hoạt động của dataset, xem HTMLElement.dataset.
Giá trị
Một DOMStringMap.
Ví dụ
html
<div>
<svg viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg">
<text x="20" y="20" id="user" data-id="1234567890" data-user="carinaanand">
Carina Anand
</text>
</svg>
</div>
js
const el = document.querySelector("#user");
console.log(el.dataset.id); // "1234567890"
Thông số kỹ thuật
| Specification |
|---|
| HTML> # dom-dataset-dev> |
Tương thích trình duyệt
Xem thêm
- Các thuộc tính SVG
data-* - Sử dụng thuộc tính dữ liệu