0

我有这个 jquery 和表单,我希望能够从触发搜索操作中排除某些击键。有没有一种简单的方法来允许例如字母数字击键?所以我可以忽略,ctrl,shift键等......

$(function() {
  var $searchField;
  return $searchField = $('.search');
});

$searchField.focus().val($searchField.val());

$(document).on("keyup", ".search", function(e) {
  return delay(function() {
  $('.search').attr('readonly', 'readonly');
  return $('.search').parent('form').submit();
  }, 500);
});

<form accept-charset="UTF-8" action="/" method="get">
  <input class="search" focus="true" id="search" name="search" placeholder="Search" type="text" value="">
 </form>
4

1 回答 1

1
$(document).on("keyup", ".search", function (e) {
    if (e.keyCode == 16 || e.keyCode ==17) { //shift or ctrl
        //Do nothing 
    } else {
        return delay(function () {
            $('.search').attr('readonly', 'readonly');
            return $('.search').parent('form').submit();
        }, 500);
    }
});

演示

于 2013-08-14T11:54:54.730 回答