javascript防止keyup的默认值 [英] javascript prevent default for keyup
本文介绍了javascript防止keyup的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
$(document).on('keyup', 'p[contenteditable="true"]', function(e) {
if(e.which == 13) {
e.preventDefault();
$(this).after('<p contenteditable = "true"></p>');
$(this).next('p').focus();
} else if((e.which == 8 || e.which == 46) && $(this).text() == "") {
e.preventDefault();
alert("Should remove element.");
$(this).remove();
$(this).previous('p').focus();
};
});
我想在按下某个键时阻止默认操作。 preventDefault
适用于 keypress
但不适用于 keyup
。有没有办法防止 $(文件).on('keyup')
?
I would like to prevent the default action when a key is pressed. preventDefault
works for keypress
but not keyup
. Is there a way to prevent the defualt for $(document).on('keyup')
?
推荐答案
没有。 keyup
在默认操作后触发。
No. keyup
fires after the default action.
keydown
和 keypress
是您可以阻止默认值的地方。
如果没有停止,则默认发生并且 keyup
被解雇。
keydown
and keypress
are where you can prevent the default.
If those aren't stopped, then the default happens and keyup
is fired.
这篇关于javascript防止keyup的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文