回答編集履歴
1
調整
test
CHANGED
@@ -25,3 +25,47 @@
|
|
25
25
|
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
# 調整
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
|
33
|
+
<script>
|
34
|
+
|
35
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
36
|
+
|
37
|
+
[].forEach.call(document.querySelectorAll('a:not(.apple):not(.orange)'),function(x){
|
38
|
+
|
39
|
+
x.addEventListener('click', function(e) {
|
40
|
+
|
41
|
+
if(e.currentTarget.href === window.location.href) {
|
42
|
+
|
43
|
+
alert("oops");
|
44
|
+
|
45
|
+
e.preventDefault();
|
46
|
+
|
47
|
+
e.stopPropagation();
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
});
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
});
|
56
|
+
|
57
|
+
</script>
|
58
|
+
|
59
|
+
<a href="#apple" class="apple">apple</a>
|
60
|
+
|
61
|
+
<a href="#orange" class="orange">orange</a>
|
62
|
+
|
63
|
+
<a href="#both" class="apple orange">both</a>
|
64
|
+
|
65
|
+
<a href="#none" class="">not set</a>
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
not setを2度押しするとoopsが表示されます
|
70
|
+
|
71
|
+
しかしすでに1回めのクリックで#noneに飛んでいるのでe.preventDefault()する意味がないような?
|