2011-03-25 4 views
1

웹 사이트에서 작업 중이며 클라이언트는 웹 사이트의 다른 모든 페이지에서 서비스 페이지의 동적 콘텐츠에 액세스 할 수 있기를 원하지만 아래 코드는 첫 번째 페이지 클릭 한 앵커가 아닌 "div"를 목록에 추가하십시오.다른 페이지에서 동적 콘텐츠에 액세스

$(document).ready(function() 
{ 
    //hide the all div except first one 
    $('.msg_body:not(:first)').hide(); 

    //when the anchor is clicked content opens like shutter 
    $("a.linkclass").click(function() 
    { 
     $('.msg_body').hide("slow"); 
     $($(this).attr("href")).show("slow"); 
    });  
}); 

이 사이트는 www.quantumrenovations.net

답변

1

당신 만이 링크를 클릭하면 또한 페이지가로드 (한 번만 발생했을 때, 당신은 URI에 앵커를 잡을 필요가 흥미로운 DIV를 보여 , 페이지가로드 될 때).

이 시도 :

$(document).ready(function() { 
    //hide the all div except first one 
    $('.msg_body:not(:first)').hide(); 

    // create a reusable "generic" function 
    var showContent = function(anchor) { 
     $('.msg_body').hide("slow"); 

     $(anchor).show("slow"); 
    }; 

    // click event calls the "generic" function 
    $("a.linkclass").click(function() { 
     showContent($(this).attr("href")); 
    }); 

    // this is where you need to catch the anchor in the URI 
    var _tagIndex = window.location.href.indexOf('#'); 
    if (_tagIndex>=0) { 
     showContent(window.location.href.substr(_tagIndex)); 
    } 
}); 
+0

너무 Yanick을 주셔서 감사합니다. 그것은 완벽하게 작동합니다! –

+0

듣기가 기쁩니다! 이 답을 수락하기 위해 "확인"마크를 클릭하는 것을 잊지 마십시오. :) –

관련 문제