回答編集履歴

1

調整

2019/10/30 06:59

投稿

yambejp
yambejp

スコア114845

test CHANGED
@@ -6,15 +6,17 @@
6
6
 
7
7
  $('input').on('keydown',function(e){
8
8
 
9
- if(e.which==13){
9
+ if(e.which==13){ // キー入力がエンターだった場合
10
10
 
11
- var inp=$(this).closest('form').find('input');
11
+ var inp=$(this).closest('form').find('input'); // input要素を全部掴んで
12
12
 
13
- var next=inp.index(this)+1;
13
+ var next=inp.index(this)+1; // 自分が何番目か数え1を足したのが次の要素
14
14
 
15
- if(inp.length<=next) next=0;
15
+ if(inp.length<=next) next=0;
16
16
 
17
+ // 次要素のindexがinpの要素数を超えたらオーバーフローするのでindexを0に戻す
18
+
17
- inp.eq(next).trigger('focus');
19
+ inp.eq(next).trigger('focus'); // 次要素(inp.eq(next))にフォーカスを当てる
18
20
 
19
21
  }
20
22