我有以下代码:
$(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
。是否有一种方法可以防止 $(document).on('keyup')
的默认操作?