let textPosition = document.getElementsByClassName(‘text‘)[0]; var range = window.getSelection();//创建range range.selectAllChildren(textPosition);//range 选择obj下所有子内容 range.collapseToStart();//光标移至最前 range.collapseToEnd();//光标移至最后
原文:https://www.cnblogs.com/wangjae/p/15229493.html