值
一個 Node 物件。
示例
此示例在點選輸入欄位內部時記錄插入符號位置的 offsetNode 和 offset。
html
<input aria-label="text field" value="Click inside this input field" />
js
document.querySelector("input").addEventListener("click", (event) => {
const x = event.clientX;
const y = event.clientY;
const caret = document.caretPositionFromPoint?.(x, y);
if (!caret) {
log("Not supported");
return;
}
const node = caret.offsetNode;
const offset = caret.offset;
log(`offsetNode: ${node}`);
log(`offset: ${offset}`);
});
規範
| 規範 |
|---|
| CSSOM 檢視模組 # dom-caretposition-offsetnode |
瀏覽器相容性
載入中…