ExecCommand函数的定义是否为粗体? [英] Definition of ExecCommand function for bold?
问题描述
ExecCommand提供了一种在iFrame中加粗文本,使其变为斜体,加下划线等的方法。
ExecCommand offers a way to bold text inside iFrame, make it italic, underline it etc.
但它缺少创建<的选项;引用>
或< strong>
或< em>
(有 formatBlock
但仅限于块元素而不是内联元素。)
But it's missing an option to create <cite>
or <strong>
or <em>
(there is formatBlock
but only for block elements and not inline ones).
我想使用ExecCommand函数来创建< cite>
- 有没有办法实现这个目标?显然,我希望保持完美无瑕的解析,例如粗体
,而不是像 surroundContents
那样在使用时会失败它在相同的选择上两次。
I'd like to use ExecCommand function for creating <cite>
- is there any way to achieve this? And obviously I want to maintain flawless parsing like in case of bold
and not something like surroundContents
which will fail when you use it twice on the same selection.
我正在寻找ExecCommand粗体命令的定义或使用现有的commants完美地添加<的方法;举>
。有什么建议?我无法从浏览器的功能中提取它。当我尝试这样做时,它会说本机代码。
I'm looking for a definition of ExecCommand bold command or a way to use existing commants to flawlessly add <cite>
. Any suggestions? I couldn't extract it from browser's functions. It says "native code" when I try to do that.
推荐答案
我看到之前评论中提到过CKEditor: )这就是我们处理执行命令的方式:
I see that CKEditor was mentioned in one of previous comments :) So this is how we handle executing commands:
- 我们手动执行一切。正如您所看到的,DOM API是不够的,浏览器之间的实现也不同,所以我想(但我没有检查过),在一个浏览器中包含一些带有应用样式的文本的HTML在其他浏览器中不起作用(因为应用了一个浏览器)
strong
和第二个b
或span
具有内联样式)。 - 首先,我们需要定制范围和选择实现。你不能使用它们,但有一个很酷的 Rangy lib。
- 您需要的下一个组件是一组应用,删除和检查样式的方法。这是我们的impl 。
- 最后一个组件是微不足道的 - 自定义命令,因为模仿W3C的API和想法很方便。
- We do everything manually. As you can see DOM API isn't sufficient and implementations differ between browsers, so I guess (but I haven't checked this) that HTML containing some text with applied styles in one browser won't work in other (because one browser applied
strong
and secondb
orspan
with inline style). - First of all we need custom Range and Selection implementations. You can't use them, but there's a cool Rangy lib.
- Next component that you need is set of methods for applying, removing and checking styles. Here's our impl.
- And the last component is trivial - custom commands, because it's convenient to mimic W3C's APIs and ideas.
这篇关于ExecCommand函数的定义是否为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!