是否可以检测设计模式中当前光标位置处切换的内容?
我正在开发一个自定义的富文本编辑器,我想知道是否可以将光标放在某处并发现哪些命令(即粗体、斜体、justifyCenter 等)当前处于活动/切换状态。显然,浏览器在设计模式下会跟踪这一点。例如,如果我在 iframe 内有这样的文本:
你好世界!
然后我将光标放在“world”一词内,有什么方法可以确定“bold”当前已切换,而无需解析字符串并发现我位于标签之间?
我想要这样的原因是这样我可以检测编辑器上的选择更改事件,然后突出显示与当前在该位置切换的内容相对应的适当按钮
I am working on a customized rich text editor and I am wondering if it is possible to place my cursor somewhere and discover what commands (i.e. bold, italic, justifyCenter, etc.) are currently active/toggled. Obviously, the browser, while in designMode, is keeping track of this. For example, if I have text inside of the iframe like this:
hello world!
and then i place my cursor inside of the word "world", is there any way to figure out that 'bold' is currently toggled without parsing the string and discovering that I am between tags?
The reason I want something like this is so that I can detect a selectionchange event on the editor and then highlight the appropriate button(s) corresponding to what is currently toggled at that position
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
document
的queryCommandState()
方法执行以下操作:请参阅 MDC、MSDN和Dottoro。
The
queryCommandState()
method ofdocument
does this:See MDC, MSDN and Dottoro.