TextFormat: underlineStyle property

Khả dụng hạn chế

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

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính underlineStyle của giao diện TextFormat cho biết kiểu đường gạch chân cần được áp dụng cho phạm vi văn bản đang được định dạng.

Giá trị

Một String có một trong các giá trị sau:

  • "none": Không có đường gạch chân.
  • "solid": Đường gạch chân liền nét.
  • "double": Đường gạch chân đôi.
  • "dotted": Đường gạch chân chấm.
  • "dashed": Đường gạch chân gạch nối.
  • "wavy": Đường gạch chân lượn sóng.

Ví dụ

Đọc kiểu đường gạch chân cần áp dụng

Ví dụ sau cho thấy cách sử dụng thuộc tính underlineStyle của sự kiện textformatupdate để xác định kiểu đường gạch chân cần áp dụng cho văn bản đang được định dạng. Lưu ý rằng callback của trình nghe sự kiện trong ví dụ này chỉ được gọi khi sử dụng cửa sổ IME để soạn thảo văn bản.

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}.`,
    );
  }
});

Thông số kỹ thuật

Thông số kỹ thuật
EditContext API
# dom-textformat-underlinestyle

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

Xem thêm