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

浏览器兼容性

另见