js 游標位置處理

2022-02-09 16:57:21 字數 534 閱讀 6456

/**

* 獲取選中文字

* 返回selection,tostring可拿到結果,selection含有起始游標位置資訊等

**/function

getselecttext()

/*** 獲取游標位置

* 對 input、textarea有效,對contenteditable:true方式不生效

**/function

getcursortposition (textdom)

else

if (textdom.selectionstart || textdom.selectionstart == '0')

return

cursorpos;

} /*** 設定游標位置

* 有效物件同游標獲取

**/function

setcaretposition(textdom, pos)

else

if(textdom.createtextrange)

}

js獲取游標位置

var tt elsereturn t.selectionstart 設定游標位置 method setcursorposition param t element param p number return setcursorposition function t,p 插入到游標後面 method...

js獲取游標,設定游標位置

直接貼 作為日常開發筆記 設定游標位置 params ele 輸入框元素 params pos 需要將游標設定的位置 author 2018 09 29 setcaretposition ele,pos else if ele.createtextrange 獲取游標在輸入框中相對位置 param ...

js獲取指定元素的游標位置,並在游標位置後增加值

html js var mouseplace getcursortposition document.getelementsbyclassname showoptions content 0 獲取游標的位置insertspan showoptions content mouseplace,測試資料 ...