回答編集履歴

1

ついき

2019/09/18 03:25

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -29,3 +29,37 @@
29
29
  <input type="text" class="js-count"><input type="text" class="show-count" readonly tabindex="-1"><br>
30
30
 
31
31
  ```
32
+
33
+
34
+
35
+ # 追記
36
+
37
+ どうしてもidやクラスを変えたくないならこうです
38
+
39
+ ```javascript
40
+
41
+ <script>
42
+
43
+ $(function(){
44
+
45
+ $('#js-count01,#js-count02,#js-count03,#js-count04').on('keyup',function(){
46
+
47
+ var num=$(this).attr('id').substr(-2);
48
+
49
+ $('.show-count'+num).val($(this).val().length);
50
+
51
+ });
52
+
53
+ });
54
+
55
+ </script>
56
+
57
+ <input type="text" id="js-count01"><input type="text" class="show-count01" readonly tabindex="-1"><br>
58
+
59
+ <input type="text" id="js-count02"><input type="text" class="show-count02" readonly tabindex="-1"><br>
60
+
61
+ <input type="text" id="js-count03"><input type="text" class="show-count03" readonly tabindex="-1"><br>
62
+
63
+ <input type="text" id="js-count04"><input type="text" class="show-count04" readonly tabindex="-1"><br>
64
+
65
+ ```