제이쿼리 메뉴활성화 관련 질문드려요
본문
http://stackoverflow.com/questions/4866284/jquery-add-class-active-on-menu/4866319#answer-4866848
php 를 사용하지않고, 자바스크립트로 현재 페이지에 해당도ㅣ는 메뉴를 활성화 시키려고합니다.
stackoverflow 사이트에서 안되는 영어로..해당 자문을 여러방면으로 구하다가 아래 소스가 가장 이상적이라는..
느낌.
이와서.. 계속 시도해보지만 ...도저히 안되네요 ㅠㅠ
고수님들..도와주세요..
clist1.html 에 대해서 해당 페이지일때는 아래와 같이 간단히 됩니다..
var path = window.location.href;
$('#cm li a').each(function() {
if (this.href === path) {
$(this).parent().addClass('on');
}
});
하지만. clist1.html 아래의 서브페이지 clist1.html?cate_no=123123 예를 들어 이와같이 뒤에 ~@!#@!#가 붙는다면
...문제가생기져..ㅠㅠ
방법이 없을가요?
php를 사용안하구요!
<div id="cm">
<li><a href="/product/clist1.html" >a</a></li>
<li><a href="/product/clist2.html" >b</a></li>
<li><a href="/product/clist3.html" >c</a></li>
</div>
<script>
var url = window.location.pathname;
urlRegExp = new RegExp(url.replace(/\/$/,''));
$('#cm a').each(function(){
if(urlRegExp.test(this.href)){
$(this).addClass('on');
}
});
</script>
답변을 작성하시기 전에 로그인 해주세요.