选项卡索引在html中的提交按钮上不起作用?

选项卡索引在html中的提交按钮上不起作用?,html,asp.net-mvc-3,Html,Asp.net Mvc 3,我创建了这样的设计。但提交Tabindex不起作用。请检查此项并让我知道 <input id="id" type="text" value="" class="input" tabindex="1"/> <input id="userName" type="text" value="" tabindex="2"/> <input type="button" value="search" onclick="searchbyrole()" tabind

我创建了这样的设计。但提交Tabindex不起作用。请检查此项并让我知道

 <input id="id" type="text" value=""  class="input" tabindex="1"/>
  <input id="userName" type="text" value=""   tabindex="2"/>
 <input  type="button" value="search" onclick="searchbyrole()"  tabindex="3"/>


输入用户名后,单击enter not firing search action(输入不触发搜索操作)。请告诉我为什么tabindex不能正确执行。

您可以使用以下代码执行此操作:

<script type="text/javascript">
    $(document).bind('keydown', function (e) {
        if (e.which === 13) { // return
            $('#IdOfTheButton').trigger('click');
        }
    });
</script>

$(文档).bind('keydown',函数(e){
如果(e.which==13){//返回
$('#IdOfTheButton')。触发器('click');
}
});

它似乎对我有用-我更改了索引只是为了确定:您真的需要使用
tabindex
?如果您的字段都按照您希望它们被使用的顺序放在标记中,那么最好完全省略它们。代码不会重现这个问题。请提供实际证明问题的最低限度的文档。还要指定测试的浏览器。