KeyPress或KeyDown事件没有得到html元素的buind
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." );
});
更多相关文章
- 通过html5 touch事件封装手势识别组件
- HTML5移动开发技术要点总结及各事件含义
- HTML5晃动DeviceMotionEvent事件
- 用一个听众听多个事件?
- 如何通过mysql查询获得具有不同时区的事件的日,小时,分钟,秒
- 【文档】五、Mysql Binlog事件结构
- 向数据库添加1的PHP Onclick事件(SQL)
- 如何最好地处理重复日历事件的异常
- 前端笔记之JavaScript(十)深入JavaScript节点&DOM&事件