回答編集履歴
1
修正
answer
CHANGED
@@ -19,15 +19,15 @@
|
|
19
19
|
<input id="text3" type="text" placeholder="3">
|
20
20
|
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
21
21
|
<script>
|
22
|
-
var i = 4;
|
22
|
+
var i = 4, s = "input[id^=text]";
|
23
23
|
$("#button1").on("click", function () {
|
24
24
|
$("body").append("<input id=text" + i + " type='text' placeholder=" + i + ">\n");
|
25
25
|
i += 1;
|
26
26
|
});
|
27
27
|
|
28
|
-
$(document).on("keyup",
|
28
|
+
$(document).on("keyup", s, function (e) {
|
29
29
|
if (e.keyCode === 13) {
|
30
|
-
$(this).attr("id") === $(
|
30
|
+
$(this).attr("id") === $(s).eq(-1).attr("id") ? $(this).prevAll(s).eq(-1).focus() : $(this).nextAll(s).eq(0).focus();
|
31
31
|
}
|
32
32
|
});
|
33
33
|
</script>
|