回答編集履歴
1
chousei
answer
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
別解
|
2
2
|
```javascript
|
3
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
4
3
|
<script>
|
5
4
|
$(function(){
|
6
5
|
$(':button').on('click',function(){
|
7
|
-
var reg=/^js-btn([1-4])$/;
|
6
|
+
var reg=/^js-btn([1-4])$/; /* ← ここ条件 1~4*/
|
8
7
|
if((l=[].filter.call($(this).prop('classList'),function(x){
|
9
8
|
return x.match(reg);
|
10
9
|
}).map(function(x){
|
11
10
|
return x.match(reg)[1];
|
12
11
|
})).length>0){
|
12
|
+
$(this).next(l.map(function(x){
|
13
|
+
return '.js-child'+x;
|
13
|
-
|
14
|
+
}).join(",")).slideToggle('fast');
|
14
15
|
}
|
15
16
|
});
|
16
17
|
});
|
@@ -21,10 +22,11 @@
|
|
21
22
|
<input type="button" value="3" class="hoge js-btn3 fuga"><span class="js-child3">hoge3</span><br>
|
22
23
|
<input type="button" value="4" class="hoge js-btn4 fuga"><span class="js-child4">hoge4</span><br>
|
23
24
|
<hr>
|
24
|
-
<input type="button" value="5" class="hoge js-btn5 fuga"><span class="js-child5">うごかない
|
25
|
+
<input type="button" value="5" class="hoge js-btn5 fuga"><span class="js-child5">hoge5(うごかない) btn=5が範囲外</span><br>
|
25
|
-
<input type="button" value="
|
26
|
+
<input type="button" value="1" class="hoge js-btn1 fuga"><span class="js-child2">hoge2(うごかない) btn=1でchild=2</span><br>
|
26
27
|
<hr>
|
27
28
|
<input type="button" value="1,2" class="hoge js-btn1 js-btn2 fuga"><span class="js-child1">hoge1</span><br>
|
28
29
|
<input type="button" value="1,2" class="hoge js-btn1 js-btn2 fuga"><span class="js-child2">hoge2</span><br>
|
29
30
|
|
31
|
+
|
30
32
|
```
|