在asp.net导航中将cssClass添加到CurrentNode
本文关键字:cssClass 添加 CurrentNode asp net 导航 | 更新日期: 2023-09-27 18:28:54
这是我的代码:
<div class="Cat-list unselectable" style="font-weight:bold;">
<div class="right-bar-nav-item">
<asp:HyperLink runat="server" ID="lnkHome" NavigateUrl="~/Default.aspx">Home</asp:HyperLink>
</div>
<asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1">
<ItemTemplate>
<div class="right-bar-nav-item">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' ToolTip='<%# Eval("description") %>'><%# Eval("Title") %></asp:HyperLink>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<div style="clear:both;"></div>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
我想把类".selected"赋予当前节点。示例:如果它的Default.aspx,那么它应该从<div class="right-bar-nav-item">
更改为该<div class="right-bar-nav-item selected">
$(function(){
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/'/$/,'') + "$");
// now grab every link from the navigation
$('.menu a').each(function(){
// and test its normalized href against the url pathname regexp
if(urlRegExp.test(this.href.replace(/'/$/,''))){
$(this).addClass('selected');
}
});
});
以下是如何在javascript中做到这一点。