更新时间:2023-12-01 22:19:16
Ok I kinda figured it out now.
It's not the best (read cleanest) solution, but it works for me.
Only have tested this on Chrome, but I think other browsers will work the same.
I ended up doing this:
$('div[contenteditable=true]').keydown(function(e) {
// trap the return key being pressed
if (e.keyCode == 13) {
// insert 2 br tags (if only one br tag is inserted the cursor won't go to the second line)
document.execCommand('insertHTML', false, '<br><br>');
// prevent the default behaviour of return key pressed
return false;
}
});