Avoid createElement function if it's inside a
  • element (contentEditable)
  • 前端 未结 1 868
    借酒劲吻你
    借酒劲吻你 2021-01-07 10:01

    I\'m using this function in order to replace

    New Divs
    with
    in break lines on contentEditable divs using Safari an
    相关标签:
    1条回答
    • 2021-01-07 10:25

      First, use keyup as the event name, keypress works only on Firefox.

      Second, e.which is not always available. Use e.keyCode primarily, and fall back to e.which:

      var code = e.keyCode || e.which;
      if (code == 13) {
        // your code here..
      }
      

      Third, if you need to cancel default events fired in the key-press, you might want to throw in a preventDefault() inside your event handler routine. Make sure it's the first line.

      function(e){
         e.preventDefault();
       ..
      }
      
      0 讨论(0)
    提交回复
    热议问题