when we are pressing any key event not getting fired.

当我们按任何关键事件而不被解雇时。

<html>
  <body>
    <div id="myP" contentEditable="true">
        This is a paragraph. you can edit me, i am editable.
        <span contenteditable="false" class="go" id="go">
            <strong >This is strong thing</strong>
        </span> after strong
    </div>
  </body>
</html>

//script part

$("#go").keydown(function() {
  debugger;
  alert( "Handler for .keydown() called." );
});

when we set contentEditable = true then we can edit content of that element in my case I am having span inside div and i want to delete that span on backspace key press. but it is getting navigate me to previous page. Means it is redirecting me to previous page according to history.

当我们设置contentEditable = true然后我们可以编辑该元素的内容,在我的情况下,我在div中有跨度,我想在退格键按下时删除该跨度。但它正在引导我前一页。意味着它根据历史将我重定向到上一页。

1 个解决方案

#1


My guess is that you should take into consideration that .keydown is fired if you press a key while inside an input.

我的猜测是,如果你在输入内部按一个键,你应该考虑.keydown被触发。

<input contenteditable="false" class="go" id="go">

You could listen for all events if you attach your handler on the body instead of the span:

如果您将处理程序附加到正文而不是跨度,则可以侦听所有事件:

$("body").keydown(function() {
  debugger;
  alert( "Handler for .keydown() called." );
});

更多相关文章

  1. 通过html5 touch事件封装手势识别组件
  2. HTML5移动开发技术要点总结及各事件含义
  3. HTML5晃动DeviceMotionEvent事件
  4. 用一个听众听多个事件?
  5. 如何通过mysql查询获得具有不同时区的事件的日,小时,分钟,秒
  6. 【文档】五、Mysql Binlog事件结构
  7. 向数据库添加1的PHP Onclick事件(SQL)
  8. 如何最好地处理重复日历事件的异常
  9. 前端笔记之JavaScript(十)深入JavaScript节点&DOM&事件

随机推荐

  1. NacosSync多集群迁移
  2. 递归就这么简单
  3. 学了这么久java反射,你知道class.forName
  4. 华为HMS Core音频服务,让有声世界更动听
  5. Springboot2.x整合异步任务
  6. MyBatis之Mapper XML 文件详解(三)-Resul
  7. 为什么不推荐使用finalize方法,来看看对垃
  8. MyBatis之Mapper XML 文件详解(二)-sql和
  9. 一个简单的案例帮你理解什么是SpringIOC(
  10. MYSQL认证