MathMLElement:blur() 方法

Baseline 已廣泛支援

此功能已成熟,並且在眾多裝置和瀏覽器版本上都能正常工作。自 2023 年 1 月以來,它已在各瀏覽器中可用。

MathMLElement 介面的 blur() 方法將鍵盤焦點從當前的 MathML 元素上移除。

語法

js
blur()

引數

無。

返回值

無(undefined)。

示例

從 MathML 元素上移除焦點

HTML

html
<div>
  <math>
    <msup id="myMath" tabindex="0">
      <mi>x</mi>
      <mn>2</mn>
    </msup>
  </math>
  <button id="focusButton">Focus the Math</button>
  <button id="blurButton">Blur the Math</button>
</div>

JavaScript

js
const mathElement = document.getElementById("myMath");
const focusButton = document.getElementById("focusButton");
const blurButton = document.getElementById("blurButton");

// Focus the MathMLElement when the "Focus" button is clicked
focusButton.addEventListener("click", () => {
  mathElement.focus();
});

// Blur the MathMLElement when the "Blur" button is clicked
blurButton.addEventListener("click", () => {
  mathElement.blur();
});

結果

規範

規範
HTML
# dom-blur-dev

瀏覽器相容性

另見