Skip to content
New issue

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

JavaScript 获取选中内容 #98

Open
bojue opened this issue Jul 18, 2020 · 0 comments
Open

JavaScript 获取选中内容 #98

bojue opened this issue Jul 18, 2020 · 0 comments

Comments

@bojue
Copy link
Owner

bojue commented Jul 18, 2020

JavaScript在开发文档的过程中,需要获取选中的内容进行设置,这里整理一下相关知识点。

与用户选中区域相关的两个对象分别是Selection和Range对象。

  • Selection:表示用户选中的文本区域
let selection = window.getSelection();
let range = selection.getRangeAt(0)
let selText= selection && selection.toString();

selection 就是一个Selection对象,range表示一个Range对象,selText表示选中的文本

##注意:仅在Chrome下测试完成,IE需要兼容处理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant