HTMLElement: thuộc tính accessKeyLabel

Khả dụng hạn chế

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

Thuộc tính chỉ đọc HTMLElement.accessKeyLabel trả về một chuỗi chứa phím truy cập do trình duyệt gán cho phần tử (nếu có); nếu không thì trả về một chuỗi rỗng.

Ví dụ

JavaScript

js
const btn = document.getElementById("btn1");
const shortcutLabel = btn.accessKeyLabel || btn.accessKey;
btn.title += ` [${shortcutLabel.toUpperCase()}]`;

btn.onclick = () => {
  const feedback = document.createElement("output");
  feedback.textContent = "Đã nhấn!";
  btn.insertAdjacentElement("afterend", feedback);
};

HTML

html
<button accesskey="h" title="Chú thích" id="btn1">Di chuột qua tôi</button>

Kết quả

Đặc tả kỹ thuật

Thông số kỹ thuật
HTML
# dom-accesskeylabel

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

Xem thêm