回答編集履歴
1
調整
answer
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
<script>
|
|
3
3
|
$(function(){
|
|
4
4
|
$('input').on('keydown',function(e){
|
|
5
|
-
if(e.which==13){
|
|
5
|
+
if(e.which==13){ // キー入力がエンターだった場合
|
|
6
|
-
var inp=$(this).closest('form').find('input');
|
|
6
|
+
var inp=$(this).closest('form').find('input'); // input要素を全部掴んで
|
|
7
|
-
var next=inp.index(this)+1;
|
|
7
|
+
var next=inp.index(this)+1; // 自分が何番目か数え1を足したのが次の要素
|
|
8
|
-
if(inp.length<=next) next=0;
|
|
8
|
+
if(inp.length<=next) next=0;
|
|
9
|
+
// 次要素のindexがinpの要素数を超えたらオーバーフローするのでindexを0に戻す
|
|
9
|
-
inp.eq(next).trigger('focus');
|
|
10
|
+
inp.eq(next).trigger('focus'); // 次要素(inp.eq(next))にフォーカスを当てる
|
|
10
11
|
}
|
|
11
12
|
})
|
|
12
13
|
$('#button').on('click',function(){
|