MathMLElement: 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 January 2023.

Thuộc tính chỉ đọc dataset của giao diện MathMLElement cung cấp quyền truy cập đọc/ghi vào các thuộc tính dữ liệu tùy chỉnh (data-*) trên các phần tử. Nó hiển thị một bản đồ các chuỗi (DOMStringMap) với một mục cho mỗi thuộc tính data-*.

Bản thân thuộc tính dataset có thể đọc nhưng không thể ghi trực tiếp. Thay vào đó, tất cả các lần ghi phải đến các thuộc tính riêng lẻ trong dataset, đại diện cho các thuộc tính dữ liệu.

Giá trị

Một DOMStringMap.

Ví dụ

html
<div>
  <math>
    <msup id="equation" data-value="-1" data-equation="euler">
      <mi>e</mi>
      <mrow><mi>i</mi> <mi>π</mi></mrow>
    </msup>
    <mo>+</mo>
    <mn>1</mn>
    <mo>=</mo>
    <mn>0</mn>
  </math>
</div>
js
const el = document.querySelector("#equation");

console.log(el.dataset.value); // "-1"
console.log(el.dataset.equation); // "euler"

Kết quả

Thông số kỹ thuật

Specification
HTML
# dom-dataset-dev

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

Xem thêm