为元素绑定监听键盘上的enter键被按下事件的方法

$("someElement").on("keydown", function(event){

  var key = event.which;

  if(key == 13){

    e.preventDefault();

    doSomething();

  }

});

IE使用event对象的keyCode属性储存被按下的键。而其它浏览器使用event的which属性。

jquery封装后,统一使用which属性

原文地址:https://www.cnblogs.com/charling/p/3355827.html