回答編集履歴

1

修正

2017/06/30 01:13

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -6,19 +6,15 @@
6
6
 
7
7
  クラスの区切りは空白文字なので、sections_aの後ろのカンマが悪さをします。
8
8
 
9
-
10
-
11
-
12
-
13
- こんな感じでHTMLCOllectionで掴んで、prototypeで調整
9
+ その上で、こんな感じでHTMLCOllectionで掴んで、prototypeで調整
14
10
 
15
11
  ```javascript
16
12
 
17
13
  window.onload=function(){
18
14
 
19
- a.addEventListener('click',function(){console.log('sec_a');});
15
+ a.addEventListener('click',function(){console.log('sec_a');},true);
20
16
 
21
- b.addEventListener('click',function(){console.log('sec_b');});
17
+ b.addEventListener('click',function(){console.log('sec_b');},true);
22
18
 
23
19
  }
24
20
 
@@ -28,11 +24,13 @@
28
24
 
29
25
  var b= document.getElementsByClassName('sections_b');
30
26
 
31
- HTMLCollection.prototype.addEventListener=function(x,y){
27
+ HTMLCollection.prototype.addEventListener=function(x,y,z){
28
+
29
+ if(typeof z=="undefined") z=false;
32
30
 
33
31
  Array.prototype.map.call(this,function(i){
34
32
 
35
- i.addEventListener(x,y);
33
+ i.addEventListener(x,y,z);
36
34
 
37
35
  });
38
36
 
@@ -44,6 +42,12 @@
44
42
 
45
43
  <div class="sections_a sections_b">test</div>
46
44
 
45
+ <div class="sections_a">test2</div>
46
+
47
+ <div class="sections_b">test3</div>
48
+
47
49
 
48
50
 
49
51
  ```
52
+
53
+ (一部調整しました)