代码之家  ›  专栏  ›  技术社区  ›  splintor

为什么contentEditable元素拒绝Enter键?

  •  4
  • splintor  · 技术社区  · 16 年前

    我正在使用一个嵌入IE控件的应用程序来显示内容。我将该内容更改为包含 <div contentEditable="True">Hello World</div> 元素。这工作得很好,我可以编辑这个div的内容,但按Enter会被拒绝并发出哔哔声。

    当我将事件附加到该元素时,我看到按Enter键会触发keyDown事件,但不会触发keyPress。


    夹板

    3 回复  |  直到 16 年前
        1
  •  0
  •   mP.    16 年前

        2
  •  0
  •   Qarib Haider    14 年前

    我已经在IE和Firefox中检查过了,效果很好

        3
  •  0
  •   kongaraju    13 年前

    document.addEventListener('keydown', handle, false);
    

    删除它或将keydown事件添加到可编辑到stopPropagation。

    $('#target').keydown(function(e) {
     e.stopPropagation();
    });
    
    推荐文章