【发布时间】:2013-04-17 05:55:15
【问题描述】:
我有以下代码:
$(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') 的默认值?
【问题讨论】:
标签: javascript jquery