Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过html表单旋转tabindex_Javascript_Jquery_Ajax_Html - Fatal编程技术网

Javascript 通过html表单旋转tabindex

Javascript 通过html表单旋转tabindex,javascript,jquery,ajax,html,Javascript,Jquery,Ajax,Html,我有一个PHP生成的表单,用作发票接口。用户通过按tab键来完成表单。我需要在表单中旋转tab键,直到他们完成开票流程 例如,使用此表单: <form> <input type = "text" name="a" tabindex=1> <input type = "text" name="b" tabindex=2> <input type = "text" name="c" tabindex=3> <input type =

我有一个PHP生成的表单,用作发票接口。用户通过按
tab
键来完成表单。我需要在表单中旋转tab键,直到他们完成开票流程

例如,使用此表单:

 <form>

 <input type = "text" name="a" tabindex=1>
 <input type = "text" name="b" tabindex=2>
 <input type = "text" name="c" tabindex=3>
 <input type = "text" name="d" tabindex=4>
 <input type = "text" name="e" tabindex=5> 
 <input type = "text" name="f" tabindex=6>
 <input type = "button" name="g" tabindex=7>

 <input type = "submit" name="h" tabindex=8>

 </form>

我需要将制表符索引从1移到7,然后制表符应该将它们移回字段a。当我按ESC键时,它需要旋转,我需要将光标移动到h

示例-

选项卡键将光标从a->b->c->d->e->f->g->a->b->……->g移动

ESC键只需将光标移动到h


如何在HTML或javascript中实现这一点?

我使用id而不是名称。我想这会有帮助:

 <form>
     <input type = "text" id="a" tabindex=1/>
     <input type = "text" id="b" tabindex=2/>
     <input type = "text" id="c" tabindex=3/>
     <input type = "text" id="d" tabindex=4/>
     <input type = "text" id="e" tabindex=5/> 
     <input type = "text" id="f" tabindex=6/>
     <input type = "button" id="g" value="next" tabindex=7/>
     <input type = "submit" id="h" value="ok" tabindex=8/>
 </form>
    <script type="text/javascript">
    $('input').keydown(function(event){
        if(event.keyCode == 9 && $(event.target).is('#g') ){
            $('#a').focus(); 
            event.preventDefault();
        }
        else if (event.keyCode == 27){
            $('#h').focus(); 
            event.preventDefault();
        }
    });
    </script>

$('input').keydown(函数(事件){
if(event.keyCode==9&&$(event.target).is('#g')){
$('a').focus();
event.preventDefault();
}
else if(event.keyCode==27){
$('h').focus();
event.preventDefault();
}
});

我用下面的代码来回答这个问题并获得了成功

   <script> 
   window.history.forward(1); 
   document.attachEvent("onkeydown", my_onkeydown_handler); 
   function my_onkeydown_handler() 
   { 
   switch (event.keyCode) 
   { 

   case 9 :
   document.form.a.focus();
   event.keyCode = 0;
   break;

   case 27 :
   document.form.h.focus();
   event.keyCode = 0;
   break;
   } 
   } 
   </script>

窗口。历史。前进(1);
document.attachEvent(“onkeydown”,我的onkeydown处理程序);
函数my_onkeydown_handler()
{ 
开关(event.keyCode)
{ 
案例9:
document.form.a.focus();
event.keyCode=0;
打破
案例27:
document.form.h.focus();
event.keyCode=0;
打破
} 
}