字母数字脚本打破了tabindexing

时间:2016-10-20 18:28:35

标签: jquery html forms alphanumeric

我遇到的问题是我只需要一个字母数字输入字段,但问题是它打破了表格中标签的功能。



$(".alpha-only").on("keydown", function(event){
  // Allow controls such as backspace
  var arr = [8,16,17,20,35,36,37,38,39,40,45,46];

  // Allow letters
  for(var i = 65; i <= 90; i++){
    arr.push(i);
  }

  // Prevent default if not in array
  if(jQuery.inArray(event.which, arr) === -1){
    event.preventDefault();
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="alpha-only">

<input type="text">

<input type="text">
&#13;
&#13;
&#13;

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

9添加到数组以允许制表符:

var arr = [8,9,16,17,20,35,36,37,38,39,40,45,46];

<强>段

$(".alpha-only").on("keydown", function(event){
  // Allow controls such as backspace
  var arr = [8,9,16,17,20,35,36,37,38,39,40,45,46];

  // Allow letters
  for(var i = 65; i <= 90; i++){
    arr.push(i);
  }

  // Prevent default if not in array
  if(jQuery.inArray(event.which, arr) === -1){
    event.preventDefault();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="alpha-only">

<input type="text">

<input type="text">