我想限制可以按下的键。如何检查数组是否包含元素
$('.txtComments').keydown(function (event) {
var keys = new Array();
keys[0] = "8";
keys[1] = "46";
keys[2] = "37"
keys[3] = "39"
if(!(....)) //Check whether the keyCode is either of 8, 46, 37, or 39.
{
event.preventDefault();
}
});
感谢您的帮助
'变种键= [8,46,37,39]; ',那么你可以使用'$ .inArray'和'event.which' – 2013-03-05 19:06:31
尝试使用['$ .inArray'](http://api.jquery.com/jQuery.inArray/) – 2013-03-05 19:07:36
不错。停止投票。谢谢。 – Richard77 2013-03-05 19:27:39