我正在尝试显示/隐藏基于 jquery 的三个 div,使用<a href="#id">
. 但是代码不起作用。当我使用<a>
使用 rel 属性的链接进行映射时,代码工作正常。
例如:<a rel="cat1" class="selected">
默认.aspx
<div id="featuredleftdiv">
<script type="text/javascript">
var featuredposts = new ddtabcontent("featuredposts")
featuredposts.setpersist(true)
featuredposts.setselectedClassTarget("link")
featuredposts.init(10000)
</script>
<ul id="featuredposts" class="featuredposts">
<li><a href="#cat1" class="menu">a</a></li>
<li><a href="#cat2" class="menu">b</a></li>
</ul>
<div class="clear"></div>
<div id="cat1" class="featuredposts_content">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView4" runat="server" GroupItemCount="1" OnPagePropertiesChanging="ListView4_PagePropertiesChanging"></asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="cat2" class="featuredposts_content">
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView5" runat="server" GroupItemCount="1" OnPagePropertiesChanging="ListView4_PagePropertiesChanging"></asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
jQuery
在 html 的 Head 部分
<script type="text/javascript" src="Scripts/jquery-1.8.3.js"></script>
<script type="text/javascript">
$("a.menu").click(function () {
$("div.featuredposts_content").hide();
$($(this).attr('href')).show();
return false;
});
</script>