We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在开发富文本编辑器“光标位置处插入表情”功能时,用到了一个很关键的window.getSelection().getRangeAt(0)用来记录光标的位置,这里涉及到两个很关键的对象:
window.getSelection().getRangeAt(0)
The text was updated successfully, but these errors were encountered:
window.getSelection()
Sorry, something went wrong.
document.createRange()
selection.getRangeAt()
document.caretRangeFromPoint
insertNode()
selectNode(node) 当前node的父节点作为range的startContainer和endContainer。
collapse(toStart) 折叠,传true折叠到Range的起点;传false折叠到Range的终点。调用selectNode()后collapsed是true,不调用是false。
createContextualFragment(tagString) 创建DOM片段。这个方法会把range起点当作上下文节点,调用HTML fragment 解析算法或者XML语法解析算法,tagString包含了文本和标签然后把它转换成文档的片段。
setStart(startNode, startOffset)设置一次选择的Range的起点,可以是NodeList也可以是textNode。
setEnd(endNode, endOffset)设置一次选择的Range的终点,可以是NodeList也可以是textNode。
setStartAfter() 设置Range相对于Node的开始位置。
setEndAfter() 设置Range相对于另一个Node的结束位置。
No branches or pull requests
在开发富文本编辑器“光标位置处插入表情”功能时,用到了一个很关键的
window.getSelection().getRangeAt(0)
用来记录光标的位置,这里涉及到两个很关键的对象:The text was updated successfully, but these errors were encountered: