TextFormat: underlineStyle 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

TextFormat 接口的 underlineStyle 属性指示了需要应用于正在格式化的文本范围的下划线的样式。

一个 String,其值为以下之一:

  • "none":无下划线。
  • "solid":实线下划线。
  • "double":双线下划线。
  • "dotted":点线下划线。
  • "dashed":虚线下划线。
  • "wavy":波浪线下划线。

示例

读取需要应用的下划线样式

以下示例展示了如何使用 textformatupdate 事件的 underlineStyle 属性来确定需要应用于正在格式化文本的下划线样式。请注意,此示例中的事件监听器回调仅在使用 IME(输入法编辑器)窗口组合文本时调用。

html
<div id="editor"></div>
js
const editorEl = document.getElementById("editor");
const editContext = new EditContext(editorEl);
editorEl.editContext = editContext;

editContext.addEventListener("textformatupdate", (e) => {
  const formats = e.getTextFormats();

  for (const format of formats) {
    console.log(
      `IME wants to apply a ${format.underlineStyle} underline between ${format.rangeStart} and ${format.rangeEnd}.`,
    );
  }
});

规范

规范
EditContext API
# dom-textformat-underlinestyle

浏览器兼容性

另见