替换IE 11中的keyCode

Ari*_*ian 5 javascript jquery internet-explorer-11

我们使用此代码TabEnter密钥模拟密钥:

function EnterTab() {
    if (event.keyCode == 13) event.keyCode = 9;
    return false;
}
Run Code Online (Sandbox Code Playgroud)

但在IE 11中keyCode读取此代码不起作用.如何解决我的代码在IE 11中运行的问题?

Sal*_*n A 2

我们使用此代码来模拟 Tab 键和 Enter 键:
...
当我按 Enter 键时,我希望焦点转到下一个控件。

这个想法是错误的。不要将 Enter 更改为 Tab。通过拦截回车键、将焦点设置在下一个元素并取消事件来解决此问题。jQuery 解决方案:

$(function() {
  $("form").on("keypress", "input[type=text], select, textarea", function(e) {
    if (e.which === 13) {
      e.preventDefault();
      var $fields = $(this).closest("form").find(":input");
      var index = $fields.index(this);
      $fields.eq(index + 1).trigger("focus");
    }
  });
});
Run Code Online (Sandbox Code Playgroud)
input,
select,
textarea {
  box-sizing: border-box;
  margin: .5em 0;
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<form method="post">
  <p>Hitting enter inside the text fields will not submit the form</p>
  <textarea rows="4"></textarea>
  <input type="text" />
  <select>
    <option>1</option>
    <option>2</option>
    <option>3</option>
  </select>
  <select>
    <option>A</option>
    <option>B</option>
    <option>C</option>
  </select>
  <input type="text" />
  <input type="submit" value="sumbmit" />
</form>
Run Code Online (Sandbox Code Playgroud)

用于在 Internet Explorer 中进行测试的 jsFiddle