javascript - 如何在 javascript 或 jQuery 中模拟 ENTER 按键上的 TAB

标签 javascript jquery

我想更改页面中所有输入的 keydown(按键)中的键码。我想用 TAB 键码替换 Enter 键码。我该怎么做?

谢谢


编辑 1)

考虑这段代码:

<div>
    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
    </asp:RadioButtonList>
    <br />
    <br />
    <asp:TextBox ID="TextBox1" runat="server">3333</asp:TextBox>
    <br />
    <br />
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
    </asp:DropDownList>
</div>

我希望当用户在上述任何一个控件上按 Enter 时,焦点转到下一个控件。

谢谢

最佳答案

我遇到过类似的问题,我想在小键盘上按 + 以切换到下一个字段。现在,我发布了一个我认为会对您有所帮助的库。

PlusAsTab: A jQuery plugin to use the numpad plus key as a tab key equivalent.

因为你想要 enter/ 代替,你可以设置选项。通过 jQuery event.which demo 找出您要使用的 key .

JoelPurra.PlusAsTab.setOptions({
  // Use enter instead of plus
  // Number 13 found through demo at
  // https://api.jquery.com/event.which/
  key: 13
});

然后通过将 plus-as-tab="true" 添加到您要使用 enter-as-tab 的表单字段或包含这些表单字段的其他元素来启用该功能。单选按钮应该不是问题,因为它们在我的其他图书馆中,EmulateTab - 参见 autonavigation of radio buttons in that demo .

<div plus-as-tab="true">
  <!-- all focusable elements inside the <div> will be enabled -->
  <asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <!-- Radio buttons should not be a problem. -->
  </asp:RadioButtonList>
</div>

您可以在 PlusAsTab enter as tab demo 中自行尝试.

关于javascript - 如何在 javascript 或 jQuery 中模拟 ENTER 按键上的 TAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8546252/

相关文章:

Javascript,设置onclick方法语法

jquery 复选框警报

javascript - 下拉语义-UI : Keep the button value by change event

javascript - 如何在页面加载时向下滚动网页 20px-50px?

jquery - 无法在 jQuery 数据表中填充数据

javascript - select2 4.0 AJAX 预填充方法?

jquery - 试图改变 UL LI 背景颜色 jquery

javascript - 复选框未选中状态

Javascript:需要注册表单帮助

javascript 使用一个控件切换显示/隐藏 div