Accessing a dynamic content from another page
I'm working on a websites and the clients wants to be able to access the dynamic content on the services page from every other page on the website but the code below makes it to display the first "div" in the list instead of the one with the anchor that was clicked on.
$(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("h开发者_JAVA技巧ref")).show("slow");
});
});
The site is www.quantumrenovations.net
You only show the interesting DIV when you click on a link, you need to catch the anchor in the URI when the page loads also (happens only once, when the page load).
Try this :
$(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));
}
});
精彩评论