CommandEvent: source 屬性
CommandEvent 介面的source只讀屬性返回一個 EventTarget,表示呼叫給定命令的控制元件。
值
一個 EventTarget 物件。通常是 HTMLButtonElement。
示例
在下面的簡單示例中,我們設定了一個事件監聽器,用於在 CommandEvent 發生時向按鈕元素新增一個臨時類。
js
document.body.addEventListener(
"command",
(event) => {
const theButton = event.source;
theButton.classList.add("just-pressed");
setTimeout(() => {
theButton.classList.remove("just-pressed");
}, 1000);
},
{ capture: true },
);
規範
| 規範 |
|---|
| HTML # dom-commandevent-source |
瀏覽器相容性
載入中…