Make a
instead of
by pressing Enter on a contenteditable

前端 未结 2 641
梦毁少年i
梦毁少年i 2020-11-29 07:41

I\'ve written a bit of code in my keyboard event handler to insert a
in response to the press of the Enter key:

event.preventDefault(         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 08:22

    I would bind a function to the keyup event to delete and change to
    using regEx. So even if it creates strange markup, it will be fixed.

    Using jQuery:

    $('.myEditable').keyup(function(){
       var sanitazed = $(this).text().replace(//g, '').replace(/<\/div[^<]*?>/g, '
    '); $(this).text(sanitazed); });

提交回复
热议问题