When binding on the 'keydown' event on a tinyMCE editor instance, calling preventDefault() on the event does not prevent the default behavior in the editor. For example, when capturing the ENTER key being pressed with the following code:
tinymce.init({
selector: 'textarea',
setup: function (editor) {
$(editor).on('keydown', function (event) {
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
}
});
}
});
TinyMCE still inserts a line break. How can I override this behavior?
Change
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
}
to
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
event.stopPropagation();
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.