답변 1개
채택된 답변
+20 포인트
8년 전
http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/#test4">http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/#test4
jquery hashchange event 플러그인 이용해보세요.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
바트코드
8년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
$(function(){
// Bind an event to window.onhashchange that, when the hash changes, gets the
// hash and adds the class "selected" to any matching nav link.
$(window).hashchange( function(){
var hash = location.hash;
// Set the page title based on the hash.
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
// Iterate over all nav links, setting the "selected" class as-appropriate.
$('#liveEdtap a').each(function(){
var that = $(this);
that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
});
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).hashchange();
});