Avoid createElement function if it's inside a <LI> element (contentEditable)

时光毁灭记忆、已成空白 提交于 2019-12-01 01:07:28

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();
 ..
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!