JQuery 绑定回车事件 兼容ie8,ie9

$("#form-search").find('#search-query').bind('keypress', function(e) {
  var keycode;
  if(window.event){
    keycode = e.keyCode; //IE
  }
  else if(e.which){
    keycode = e.which;
  }
  if (keycode != 13) {
    return;
  }
  that.search();
  e.stopPropagation();
  return false;
});

你可能感兴趣的:(jquery)