테스트 사이트 - 개발 중인 베타 버전입니다

제이쿼리 메뉴활성화 관련 질문드려요 채택완료

유우니얌 11년 전 조회 7,551
http://stackoverflow.com/questions/4866284/jquery-add-class-active-on-menu/4866319#answer-4866848" target="_blank">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>
<div><div id="cm"></div>
<div><li><a href="/product/clist1.html" >a</a></li></div>
<div><li><a href="/product/clist2.html" >b</a></li></div>
<div><li><a href="/product/clist3.html" >c</a></li></div>
<div></div></div>
<div><script></div>
<div><div>    var url = window.location.pathname;</div>
<div>        urlRegExp = new RegExp(url.replace(/\/$/,'')); </div>
<div>        $('#cm a').each(function(){</div>
<div>            <span style="font-size: 10pt; line-height: 1.5">    if(urlRegExp.test(this.href)){</span></div>
<div>                $(this).addClass('on');</div>
<div>            }</div>
<div>        });</div>
<div></script></div></div>
<div>
</div>
<div>
댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
11년 전
 $('#cm a').each(function(){
     if(this.href.indexOf(url) > -1) 
        $(this).addClass('on'); 
     }
 });
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

유우니얌
11년 전
음...안되네요...

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인