getSelection() 和 insertNode——Javascript 文本选择
有谁知道如何将浏览器选择设置为新/独立创建的范围?我了解如何从浏览器获取文本选择,并且了解如何创建范围,但我不知道如何告诉浏览器将选择更改为我创建的范围。我本以为它会像“setSelection”之类的东西。
需要明确的是,我并不是试图导致选择文本区域 - 我正在谈论 p / div / ul 标签等。
我引用了以下网站(也许它会给您一个想法?):
http://www.quirksmode.org/dom/range_intro.html
预先感谢您的时间。
Does anyone know how to set the browser selection to a newly / independently created range? I understand how to get the text selection from the browser, and I understand how to create a range, but I don't know how to tell the browser to change the selection to the range I've created. I would have thought it would be something like "setSelection".
To be clear, I'm not trying to cause the selection of a textarea - I'm talking about p / div / ul tags etc.
I was referencing the following site (maybe it'll give you an idea?):
http://www.quirksmode.org/dom/range_intro.html
Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的范围在非 IE 浏览器中是 DOM
Range
,在 IE 中是TextRange
:Assuming that you have a range that is a DOM
Range
in non-IE browsers and aTextRange
in IE: