jQuery(document).ready(function(){
$("#red-products").hide();
$("#content-info").click(function(event){
$("#red-products").hide();
$("#red-information").show();
});
$("#content-product").click(function(event){
$("#red-information").hide();
$("#red-products").show();
});
$("#more").click(function(event){
load(this.href);
return false;
});
});
如您所见,默认情况下,#red-products
是隐藏的,而#red-information
是可见的。有时我希望#red-products
是可见的,而#red-information
是隐藏的,意思是像这样
http://localhost/networks2/profile.php?id=1&offset=1#products
以显示#red-products
和隐藏#red-information
。和
http://localhost/networks2/profile.php?id=1&offset=1#information
隐藏#red-products
并显示#red-information
。
如何使用jQuery从URL中读取锚点,并隐藏/显示适当的部分?
发布于 2010-12-19 21:07:42
您可以通过替换以下内容,将初始隐藏更改为基于window.location.hash
:
$("#red-products").hide();
有了这个:
$("#red-products, #red-information").hide();
$("#red-" + (window.location.hash.replace("#", "") || "information")).show();
这将在最初隐藏两者,然后显示hasd (#red-hashhere
),或者默认显示您现在拥有的#red-information
。
https://stackoverflow.com/questions/4483044
复制相似问题