execCommand 没有选择? (设置字体、大小等)
我可以让我的自定义所见即所得编辑器将样式应用于选定的文本,没问题:
pnlDocumentEditor_IFrame.document.execCommand(cmd, ui, opt)
..但我需要做的是允许用户设置字体、字体大小或粗体等,以便在此命令之后键入文本发布时将应用该样式。
这可能吗?我尝试过的所有 execCommands 似乎只适用于选定的文本。
I can get my custom WYSIWYG editor to apply styling to selected text no problem:
pnlDocumentEditor_IFrame.document.execCommand(cmd, ui, opt)
.. but what I need to be able to do is allow the user to set a font, or font size, or bold etc so that text typed AFTER this command is issued will have that style applied.
Is this possible? All execCommands I've tried seem to only work on selected text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用以下函数在某些元素上应用 execCommand,而不用鼠标选择它:
jsFiddle 示例
和示例用法:
来源:仅针对 div 设置 execcommand
Appling execCommand on certain element, WITHOUT selecting it with mouse, can be done with this function:
jsFiddle example
And example usage:
Source: set execcommand just for a div