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

링크를 누르면 class 이름이 생기는법 채택완료

김형김 7년 전 조회 3,180

  •  

    위와 같은 상황에서 링크를 눌렀을때

  •   로 

    넣는방법 알고 싶습니다 ㅠㅠ 

     

    호기심 천국에서 꼭 알려주십시오 

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

    답변 3개

    채택된 답변
    +20 포인트
    7년 전

    </p>
    
    <p>$(function(){
    
       var current = window.location.pathname;
    
       $('li a').each(function(){
    
          var link = '/' + $(this).attr('href');
    
          if (current == link){
    
            $(this).parent().addClass('active');
    
          }
    
       }); 
    
    });</p>
    
    <p>

    로그인 후 평가할 수 있습니다

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

    혹시 원하시는게 이런 거였나요? ㅎㅎ

     

    테스트 링크입니다. 

    http://www.koreacraft.kr/test1.php" href="http://www.koreacraft.kr/test1.php">http://www.koreacraft.kr/test1.php  

     

    <script src="<a href="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>" target="_blank" rel="noopener noreferrer">https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script></a></p>
    
    <p><script>
    
    $(document).ready(function(){
    
        $("li a").on("mousedown",function(){
    
            $("li").addClass("active");
    
        });
    
    });
    
    </script></p>
    
    <p><style>
    
    .active { list-style:none; }
    
    </style></p>
    
    <p>
    
    <body></p>
    
    <p><li>
    
        <a href="#">aaa </a>
    
    </li></p>
    
    <p></body></p>
    
    <p>

    로그인 후 평가할 수 있습니다

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

    해피정
    7년 전

    링크를 누르면 다시 페이지로 전환되는데...  active class 를 왜 넣어야 하는지...  

    이미 떠난 여인은 붙잡는것은 아닙니다.

    로그인 후 평가할 수 있습니다

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

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

    로그인