There seems to be a bug in IE10, where if I place an element over another element with the contenteditable attribute, the editor's caret is drawn over everything.

在IE10中似乎存在一个bug,如果我将一个元素放在另一个具有contenteditable属性的元素之上,那么编辑器的插入符号将被绘制到所有的元素之上。

You can see this behaviour below in the image below and in this jsFiddle.

您可以在下面的图片和jsFiddle看到这种行为。

I've mucked around with plenty of CSS properties, and been unable to find a solution to this. It works as expected in other browsers.

我使用了大量CSS属性,无法找到解决方案。它可以在其他浏览器中正常工作。

The reason I need this is because I am designing a WYSWIYG editor (TinyMCE fork) experience where the toolbars slide down over the text when they're required. This bug makes the caret appear over the top of the toolbar.

我之所以需要这一功能,是因为我正在设计一个WYSWIYG编辑器(TinyMCE fork),当工具条在需要的时候滑到文本上。这个错误使插入符号出现在工具栏的顶部。

The only solution I have thought of is to blur the editor's focus, and refocus it when the toolbar has disappeared. However, this will stop users from typing when the toolbar is activated, and would also cause inconsistent behaviour across browsers.

我想到的唯一解决方案是模糊编辑器的焦点,并在工具栏消失后重新调整焦点。然而,这将阻止用户在工具栏被激活时输入,并且还会导致浏览器之间的不一致行为。

Is there a workaround to this bug?

有解决这个问题的方法吗?

4 个解决方案

#1


6

There is no way to overlap the caret with another element in IE. This question was asked many times:

没有办法将插入符号与IE中的另一个元素重叠。这个问题被问了很多次:

  • Link 1
  • 链接1
  • Link 2
  • 链接2

...

But you can blur the textarea after getting the caret position (see: Caret position in textarea, in characters from the start) and then show your toolbar. After hiding the toolbar, you can focus the textarea again, setting the caret position with:

但是,您可以在获得插入符号位置后模糊textarea(请参见:textarea中的插入符号位置,从开始使用字符),然后显示工具栏。隐藏工具栏后,可以再次聚焦文本区域,设置插入符号位置为:

function setCaretPosition(elemId, caretPos) {
    var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}

See: Set keyboard caret position in html textbox

参见:在html文本框中设置键盘插入符号位置

更多相关文章

  1. javascript encodeURIComponent并将空格转换成+符号
  2. 我应该在哪里添加Yocto位烤任务来创建工作文件夹符号链接?
  3. 我的电脑认为有符号整数比-1小?
  4. Linux下符号版本原理及实现
  5. 请问有谁知道linux上生成的共享库中,使用nm列出来的符号都可以在
  6. 来点基础的--诡异的极客们的符号--流、管道和文件的耦合
  7. 特殊符号对应的ASCII码
  8. Java区分大小写字母数字和符号

随机推荐

  1. 转载:android 各种xml资源的引用方式
  2. Android开发中 ListView 不能不说的几个
  3. TextView 控件使用
  4. Android――全屏显示的两种方式
  5. Android studio中相对布局组件排列方式
  6. Activity的四种启动模式和onNewIntent()
  7. Android中设置动画循环旋转的方法
  8. Android 中文API (33) ―― Checkable
  9. EditText高度的改变
  10. Mono For Android 之 配置环境