如果是动态加载的可以给标签追加属性,用jquery或是js给具备该属性的标签添加样式就可以了!
--------------
我在以前的项目中找了个和你问题相同的解决办法,我试了可以的,你自己看看吧!
1 .abc
2 {
3 text-decoration:none;
4 color:Red;
5 background-color:#ccc;
6 }
1 <div id="content" runat="server">
2 <ul>
3 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">aaaaaaaa</asp:LinkButton></li>
4 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">bbbbbbbb</asp:LinkButton></li>
5 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">cccccccc</asp:LinkButton></li>
6 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">dddddddd</asp:LinkButton></li>
7 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">eeeeeeee</asp:LinkButton></li>
8 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">ffffffff</asp:LinkButton></li>
9 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">gggggggg</asp:LinkButton></li>
10 <li><asp:LinkButton PostBackUrl="/Default.aspx" runat="server" onclick="LinkButton_Click">hhhhhhhh</asp:LinkButton></li>
11 </ul>
12 </div>
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 foreach (Control item in this.content.Controls) {
4 if (item.GetType().Equals(typeof(LinkButton))) {
5 (item as LinkButton).CssClass = "";
6 }
7 }
8 }
9
10 protected void LinkButton_Click(object sender, EventArgs e) {
11 (sender as LinkButton).CssClass = "abc";
12 }
试试在后台绑定数据的时候,给每个Items指定CSS样式看看···
我是菜鸟,菜鸟建议不定靠的住···
$(".sidenav li a").each(function(){
$this = $(this);
if($this[0].href==String(window.location)){
$this.parent().addClass("selected");
}
});