1

我正在使用 execCommand() 从头开始​​制作所见即所得的编辑器。当用户没有选择文本时,我想禁用我的格式按钮(对齐、粗体、斜体、下划线、颜色、大小、系列等)。

我在 IFRAME 中有文档代码,在 IFRAME 之外是按钮/脚本。我使 iframe 的文档 contentEditable 并打开了 designMode。

我该怎么做才能确定是否选择了任何文本?

如果可能的话,我怎样才能知道用户的光标是否在 DIV 元素内的任意位置以进行文本对齐?我确信我可以使用它来检测光标是否也在已经加粗的文本或类似文本中。

<iframe src="/builder/ajax/load?id=1"></iframe>
<script type="text/javascript">
  function init() {
     // editor is defined in another script as the iframe.contentWindow.document
     editor.body.contentEditable = "true";
     editor.body.designMode = "on";
  }
</script>
4

1 回答 1

1

这可以使用我刚刚发现的queryCommandSupportedqueryCommandEnabled来完成!

于 2012-07-18T03:59:23.313 回答