Simditor文件設定游標在文字最後面
阿新 • • 發佈:2022-04-01
placeCaretAtEnd(el){ el.focus(); if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") { let range = document.createRange(); range.selectNodeContents(el); range.collapse(false); let sel= window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } else if (typeof document.body.createTextRange != "undefined") { let textRange = document.body.createTextRange(); textRange.moveToElementText(el); textRange.collapse(false); textRange.select(); } }
初始化之後直接加個延時器呼叫
if( this.content ){ setTimeout(()=>{ this.placeCaretAtEnd(_editor.body[0]) },50) }
這樣就設定編輯的時候游標最後面了