2017-03-29 7 views
-1

도움을 주시면 매우 감사하겠습니다!로드 후 해시 또는 해시가 변경되면 코드가 실행됩니까?

$(window).hashchange(function(){//code;}); 

어떻게이 두 검사를 결합 않습니다 해시 변경시

if(location.hash) { //code; } 

코드를 실행 : 해시 부하에있는 경우

코드를 실행?
이 작동하지 않습니다

if(location.hash || $(window).hashchange(function() { //code; }); 

답변

0

theCode에 대한 함수를 정의 hashchange 이벤트 페이지로드 검사에의 참조를 전달 해시

function theCode() { //code; } 

if(location.hash){ 
    theCode(); 
} 

$(window).hashchange(theCode); 
직접 실행할 수있는 경우
관련 문제