質問編集履歴
1
説明文の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,20 +4,24 @@
|
|
4
4
|
|
5
5
|
【以前の質問】
|
6
6
|
|
7
|
-
https://teratail.com/questions/62574
|
7
|
+
[https://teratail.com/questions/62574](https://teratail.com/questions/62574)
|
8
8
|
|
9
9
|
|
10
10
|
|
11
11
|
少し言葉足らずで整理しきれなかったので、再質問です。
|
12
12
|
|
13
|
-
メニュー
|
13
|
+
現在開いているページのパスが書かれたメニュー(aタグ)にis_activeを付けたいと思っています。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
全て静的(CMS等動的ではない)でアコーディオンのようなアクションも付ける予定はありません。
|
18
|
+
|
19
|
+
メニューをクリックしたら該当のページに遷移する予定です。
|
14
20
|
|
15
21
|
|
16
22
|
|
17
23
|
ディレクトリの構成は下記のとおりです。
|
18
24
|
|
19
|
-
|
20
|
-
|
21
25
|
/sample1/
|
22
26
|
|
23
27
|
/sample1/example1.html(←ココを開くとうめく動作しない)
|
@@ -38,6 +42,44 @@
|
|
38
42
|
|
39
43
|
|
40
44
|
|
45
|
+
|
46
|
+
|
47
|
+
下記は、前回のベストアンサーの回答者様が教えてくれたJSです。
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
|
51
|
+
var currentPath = location.pathname.split("/");
|
52
|
+
|
53
|
+
var targetHref = "/" + currentPath[currentPath.length - 3] + "/" + currentPath[currentPath.length - 2] + "/" + currentPath[currentPath.length - 1];
|
54
|
+
|
55
|
+
targetHref = targetHref.split("index.html")[0]; //一応
|
56
|
+
|
57
|
+
//↑ここは本番サイトに合わせてください。
|
58
|
+
|
59
|
+
// 想定する結果A: /sample/ccc/example1.html
|
60
|
+
|
61
|
+
// 想定する結果B: /sample/aaa/
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
navList = $(".side__navigation").find("a");
|
66
|
+
|
67
|
+
navList.each(function(){
|
68
|
+
|
69
|
+
var myhref = $(this).attr("href");
|
70
|
+
|
71
|
+
if( myhref === targetHref ) {
|
72
|
+
|
73
|
+
$(this).addClass("is_active");
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
} );
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
41
83
|
```HTML
|
42
84
|
|
43
85
|
<!-- 【理想のHTML1】 -->
|