Selection: type 屬性
Selection 介面的只讀屬性 type 返回一個描述當前選區型別的字串。
值
描述當前選區型別的字串。可能的值為:
示例
在此示例中,每次進行新的選區時,事件處理程式都會觸發。console.log(selection.type) 將返回 Caret 或 Range,具體取決於游標是位於文字的單個點,還是已選擇了一個範圍。
js
let selection;
document.onselectionchange = () => {
console.log("New selection made");
selection = document.getSelection();
console.log(selection.type);
};
規範
| 規範 |
|---|
| Selection API # dom-selection-type |
瀏覽器相容性
載入中…