avoid ie contentEditable element to create paragraphs on Enter key

后端 未结 5 1904
小蘑菇
小蘑菇 2020-12-06 06:49

On InternetExplorer, a contentEditable DIV creates a new paragraph (

) each time you press Enter whereas Firefox creates a
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 07:28

    Yes it is possible to avoid the insertion of paragraphs by stopping the keydown event first (window.event.stopPropagation();) and then inserting the string by using insert HTML command.

    However, IE depends on this divs for setting styles etc. and you will get into trouble using
    s.

    I suggest you using a project like TinyMCE or other editors and search for an editor which behaves the way you would like, since they have all kinds of workarounds for different browser issues. Perhaps you can find an editor which uses
    s...

提交回复
热议问题