Jquery 从另一个页面访问动态内容
我正在一个网站上工作,客户希望能够从网站上的每个其他页面访问服务页面上的动态内容,但下面的代码使其显示列表中的第一个“div”,而不是单击锚的那个Jquery 从另一个页面访问动态内容,jquery,jquery-plugins,jquery-selectors,Jquery,Jquery Plugins,Jquery Selectors,我正在一个网站上工作,客户希望能够从网站上的每个其他页面访问服务页面上的动态内容,但下面的代码使其显示列表中的第一个“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
$(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当您单击链接时,只显示感兴趣的DIV,当页面加载时,您需要捕获URI中的锚(当页面加载时,仅发生一次) 试试这个:
$(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));
}
});
只有在单击链接时才显示感兴趣的DIV,当页面加载时,还需要捕获URI中的锚(当页面加载时,只发生一次) 试试这个:
$(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));
}
});