回答編集履歴

1

chousei

2019/03/15 03:30

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -1,8 +1,6 @@
1
1
  別解
2
2
 
3
3
  ```javascript
4
-
5
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
6
4
 
7
5
  <script>
8
6
 
@@ -10,7 +8,7 @@
10
8
 
11
9
  $(':button').on('click',function(){
12
10
 
13
- var reg=/^js-btn([1-4])$/;
11
+ var reg=/^js-btn([1-4])$/; /* ← ここ条件 1~4*/
14
12
 
15
13
  if((l=[].filter.call($(this).prop('classList'),function(x){
16
14
 
@@ -22,7 +20,11 @@
22
20
 
23
21
  })).length>0){
24
22
 
23
+ $(this).next(l.map(function(x){
24
+
25
+ return '.js-child'+x;
26
+
25
- $(this).next(l.map(function(x){return '.js-child'+x;}).join(",")).slideToggle('fast');
27
+ }).join(",")).slideToggle('fast');
26
28
 
27
29
  }
28
30
 
@@ -44,9 +46,9 @@
44
46
 
45
47
  <hr>
46
48
 
47
- <input type="button" value="5" class="hoge js-btn5 fuga"><span class="js-child5">うごかない:btn=5が範囲外</span><br>
49
+ <input type="button" value="5" class="hoge js-btn5 fuga"><span class="js-child5">hoge5(うごかない) btn=5が範囲外</span><br>
48
50
 
49
- <input type="button" value="5" class="hoge js-btn1 fuga"><span class="js-child2">うごかない:btn=1でchild=2</span><br>
51
+ <input type="button" value="1" class="hoge js-btn1 fuga"><span class="js-child2">hoge2(うごかない) btn=1でchild=2</span><br>
50
52
 
51
53
  <hr>
52
54
 
@@ -56,4 +58,6 @@
56
58
 
57
59
 
58
60
 
61
+
62
+
59
63
  ```