2

請求インターフェースとして使用される PHP 生成フォームがあります。ユーザーは、 を押してフォームを進めていき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に移動する必要があります。

例 -

TAB キーはカーソルを a->b->c->d->e->f->g->a->b->......->g から移動しました

ESC キー カーソルを h に移動するだけ

HTMLまたはJavaScriptでこれを行うにはどうすればよいですか?

4

2 に答える 2

2

名前の代わりに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>
于 2012-12-06T06:32:04.290 に答える
0

この質問に次のコードを使用して成功しました。

   <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>
于 2013-01-09T06:37:44.043 に答える