回答編集履歴
2
inputのほうも記述
test
CHANGED
@@ -45,3 +45,53 @@
|
|
45
45
|
</html>
|
46
46
|
|
47
47
|
```
|
48
|
+
|
49
|
+
追記
|
50
|
+
|
51
|
+
---
|
52
|
+
|
53
|
+
mukkunさんにコメントしていただいたinputを使う方法を追記します。
|
54
|
+
|
55
|
+
```HTML
|
56
|
+
|
57
|
+
<!DOCTYPE html>
|
58
|
+
|
59
|
+
<html>
|
60
|
+
|
61
|
+
<head>
|
62
|
+
|
63
|
+
<meta charset="UTF-8">
|
64
|
+
|
65
|
+
<title>タイトル</title>
|
66
|
+
|
67
|
+
</head>
|
68
|
+
|
69
|
+
<body>
|
70
|
+
|
71
|
+
<form>
|
72
|
+
|
73
|
+
<input type="number" max="999" id="text1">
|
74
|
+
|
75
|
+
</form>
|
76
|
+
|
77
|
+
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
78
|
+
|
79
|
+
<script>
|
80
|
+
|
81
|
+
$('#text1').on('input', function () {
|
82
|
+
|
83
|
+
if ($(this).val().length >= 4) {
|
84
|
+
|
85
|
+
$(this).val($(this).val().slice(0, 3));
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
});
|
90
|
+
|
91
|
+
</script>
|
92
|
+
|
93
|
+
</body>
|
94
|
+
|
95
|
+
</html>
|
96
|
+
|
97
|
+
```
|
1
修正
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
$('#text1').on('keyup', function () {
|
32
32
|
|
33
|
-
if ($(this).val().length >
|
33
|
+
if ($(this).val().length >= 4) {
|
34
34
|
|
35
35
|
$(this).val($(this).val().slice(0, 3));
|
36
36
|
|