Javascript jquery关注final选项卡上的第一个表单元素

Javascript jquery关注final选项卡上的第一个表单元素,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我试图让光标跳到窗体的第一个元素上。出于某种原因,它一直关注第二个元素而不是第一个元素。我只做了一个简单的表格 <form> <input type="text"> <input type="text"> <input type="text"> <input type="submit" value="Submit"> </form> $('form').children().keydown(function

我试图让光标跳到窗体的第一个元素上。出于某种原因,它一直关注第二个元素而不是第一个元素。我只做了一个简单的表格

<form>
  <input type="text">
  <input type="text">
  <input type="text">
  <input type="submit" value="Submit">
</form>

$('form').children().keydown(function(e) {
if (e.keyCode == 9 || e.which == 9) {
       if ($(this).is(':last-child')) {
         $(this).parent().children().first().focus();
       }
}
})

$('form').children().keydown(函数(e){
if(e.keyCode==9 | | e.which==9){
if($(this).is(':last child')){
$(this.parent().children().first().focus();
}
}
})
问题

请参阅控制台日志

按最后一个元素上的tab键时,它将聚焦第一个元素,然后执行
tab
操作,使其转到第二个元素。

解决方案 使用或
返回false
停止制表符操作


不幸的是,它也转到了第二个表单元素。@user2112618欢迎乐于帮助:)
if ($(this).is(':last-child')) {
            $(this).parent().children().first().focus();
            e.preventDefault(); // or return false;
}