我有这个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>
$(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);
}
});
DEMO