Simditor文档设置光标在文本最后面

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)
            }

 

这样就设置编辑的时候光标最后面了

posted @ 2022-04-01 12:04  天涯何处归一  阅读(57)  评论(0编辑  收藏  举报