Dealing with line Breaks on contentEditable DIV

后端 未结 7 1792
粉色の甜心
粉色の甜心 2020-11-27 12:41

I have a problem with contenteditable line breaks on SAFARI/CHROME. When I press \"return\" on a contentEditable

, instead of creating a
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 13:14

    You can simply use following command document.execCommand('insertHTML',false,'
    ');

    This command will prevent default behavior and add a tag you wish. That's all, 1 line of code

    And even easier approach.

    CSS ONLY.

    To you contenteditable element apply display:inline-block rule and this will add brs only

提交回复
热议问题