回答編集履歴

1

追記

2019/02/19 07:10

投稿

m.ts10806
m.ts10806

スコア80852

test CHANGED
@@ -3,3 +3,83 @@
3
3
  そもそもの作りのほうから見直された方が良いのではないでしょうか。
4
4
 
5
5
  hideしておいてshowではなく、入力チェックで引っかかった処理の分だけappendするやり方が本来望ましいと思います。
6
+
7
+
8
+
9
+ ----
10
+
11
+
12
+
13
+ 若干無理やりです。
14
+
15
+ errorのliを回しながら[is:containsで検索](http://kihon-no-ki.com/jquery-object-contains-text)かけます。
16
+
17
+ ```js
18
+
19
+ $(function(){
20
+
21
+ const error_node = $("#firstname").parent("p").prev("ul.errorList_text").children("li");
22
+
23
+ for(let i=0;i<error_node.length;i++){
24
+
25
+ if($(error_node[i]).is(":contains('未入力')")){
26
+
27
+ $(error_node[i]).show();
28
+
29
+ }
30
+
31
+ }
32
+
33
+ });
34
+
35
+ ```
36
+
37
+
38
+
39
+ HTMLも下記のようにして#firstname部分を変更し確認してみました。
40
+
41
+ ```html
42
+
43
+ <ul class="errorList_text">
44
+
45
+ <li style="display:none;"><img src="caution.jpg" alt="error">1小文字のみ有効です。</li>
46
+
47
+ <li style="display:none;"><img src="caution.jpg" alt="error">2未入力です。</li>
48
+
49
+ </ul>
50
+
51
+ <p>
52
+
53
+ <input type="text" id="firstname1">
54
+
55
+ </p>
56
+
57
+ <ul class="errorList_text">
58
+
59
+ <li style="display:none;"><img src="caution.jpg" alt="error">小文字のみ有効です。</li>
60
+
61
+ <li style="display:none;"><img src="caution.jpg" alt="error">未入力です。</li>
62
+
63
+ </ul>
64
+
65
+ <p>
66
+
67
+ <input type="text" id="firstname2">
68
+
69
+ </p>
70
+
71
+ <ul class="errorList_text">
72
+
73
+ <li style="display:none;"><img src="caution.jpg" alt="error">小文字のみ有効です。</li>
74
+
75
+ <li style="display:none;"><img src="caution.jpg" alt="error">未入力です。</li>
76
+
77
+ </ul>
78
+
79
+ <p>
80
+
81
+ <input type="text" id="firstname3">
82
+
83
+ </p>
84
+
85
+ ```