是否可以检测设计模式中当前光标位置处切换的内容?

发布于 2024-10-11 05:28:21 字数 277 浏览 12 评论 0原文

我正在开发一个自定义的富文本编辑器,我想知道是否可以将光标放在某处并发现哪些命令(即粗体、斜体、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撑一把青伞 2024-10-18 05:28:21

documentqueryCommandState() 方法执行以下操作:

var isBold = document.queryCommandState("bold");

请参阅 MDCMSDNDottoro

The queryCommandState() method of document does this:

var isBold = document.queryCommandState("bold");

See MDC, MSDN and Dottoro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文