문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
wiki:javascript:jstl:메뉴_클릭시_이벤트_발생 [2020/02/15 18:33] jhgong |
wiki:javascript:jstl:메뉴_클릭시_이벤트_발생 [2023/01/13 18:44] (현재) |
||
|---|---|---|---|
| 줄 12: | 줄 12: | ||
| ○ 메뉴 클릭시 해당 Navigation bar를 HighLighting 시키려면 다음과 같은 방식을 사용한다. | ○ 메뉴 클릭시 해당 Navigation bar를 HighLighting 시키려면 다음과 같은 방식을 사용한다. | ||
| - | + | <code javascript> | |
| - | + | setNavigation(); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | setNavigation(); | + | |
| - | // 메뉴 클릭시 이벤트 발생 | + | // 메뉴 클릭시 이벤트 발생 |
| - | $(" | + | $(" |
| - | $(this).parent().siblings().children(' | + | $(this).parent().siblings().children(' |
| - | $(this).addClass(' | + | $(this).addClass(' |
| - | /* 추가 작업 */ | + | /* 추가 작업 */ |
| - | } | + | } |
| - | + | </ | |
| ○ 만약 URL이 바뀌어서 해당 디렉토리 안에 있을 때 HighLighting을 유지할수 없는 경우 | ○ 만약 URL이 바뀌어서 해당 디렉토리 안에 있을 때 HighLighting을 유지할수 없는 경우 | ||
| - | + | <code javascript> | |
| - | + | var path = window.location.pathname; | |
| - | var path = window.location.pathname; | + | path = path.replace(/ |
| - | path = path.replace(/ | + | path = decodeURIComponent(path); |
| - | path = decodeURIComponent(path); | + | |
| - | /* contextRoot */ | + | /* contextRoot */ |
| - | var endIdx = path.indexOf('/', | + | var endIdx = path.indexOf('/', |
| - | var contextRoot = path.substring(0, | + | var contextRoot = path.substring(0, |
| - | var depth1Root = path.substring(0, | + | var depth1Root = path.substring(0, |
| - | if(path.indexOf('/', | + | if(path.indexOf('/', |
| - | { | + | { |
| - | endIdx = path.indexOf('/', | + | endIdx = path.indexOf('/', |
| - | depth1Root = path.substring(0, | + | depth1Root = path.substring(0, |
| - | } | + | } |
| - | // console.log(path, | + | // console.log(path, |
| - | // console.log(path); | + | // console.log(path); |
| - | $(" | + | $(" |
| - | var href = $(this).attr(' | + | var href = $(this).attr(' |
| - | // console.log(href); | + | // console.log(href); |
| - | if(href.indexOf(depth1Root)===0) | + | if(href.indexOf(depth1Root)===0) |
| - | { | + | { |
| - | $(this).addClass(' | + | $(this).addClass(' |
| - | } | + | } |
| - | } | + | } |
| - | + | </ | |
| - | ○ 이와같이 **indexOf** 혹은 **lastIndexOf** 를 사용해 적절하게 URL을 수정하는 방식을 사용한다. | + | ○ 이와같이 |