这是一个老问题。如果有人再来这里。这是给他们的:)
我就是这样做的。希望它可以帮助某人...
方法 1. 通过使用图像和代码
每个菜单项都有一对图像。一个用于活动,一个用于未选择
aspx 代码
<asp:Menu
ID="Menu1"
Width="1300px"
runat="server"
Orientation="Horizontal"
StaticEnableDefaultPopOutImage="False"
OnMenuItemClick="Menu1_MenuItemClick" >
<DynamicSelectedStyle CssClass="mSelected" />
<StaticSelectedStyle CssClass="mSelected" />
<Items>
<asp:MenuItem ImageUrl="images/selectedt1.jpg" Text="" Value="0" ></asp:MenuItem>
<asp:MenuItem ImageUrl="images/unselectedt2.jpg" Text="" Value="1"></asp:MenuItem>
<asp:MenuItem ImageUrl="images/unselectedt3.jpg" Text="" Value="2"></asp:MenuItem>
<asp:MenuItem ImageUrl="images/unselectedt4.jpg" Text="" Value="3"></asp:MenuItem>
</Items>
</asp:Menu>
css
<style type="text/css">
.mSelected {border:none;border-collapse:collapse;border-width:0px;border-color:#ffffff;}
</style>
aspx.cs 代码
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
int i = 0; // index of the menu item
if (Int32.Parse(e.Item.Value) == 0)
{
Menu1.Items[0].ImageUrl = "images/selectedt1.jpg";
Menu1.Items[1].ImageUrl = "images/unselectedt2.jpg";
Menu1.Items[2].ImageUrl = "images/unselectedt3.jpg";
Menu1.Items[3].ImageUrl = "images/unselectedt4.jpg";
}
if (Int32.Parse(e.Item.Value) == 1)
{
Menu1.Items[0].ImageUrl = "images/unselectedt1.jpg";
Menu1.Items[1].ImageUrl = "images/selectedt2.jpg";
Menu1.Items[2].ImageUrl = "images/unselectedt3.jpg";
Menu1.Items[3].ImageUrl = "images/unselectedt4.jpg";
}
if (Int32.Parse(e.Item.Value) == 2)
{
Menu1.Items[0].ImageUrl = "images/unselectedt1.jpg";
Menu1.Items[1].ImageUrl = "images/unselectedt2.jpg";
Menu1.Items[2].ImageUrl = "images/selectedt3.jpg";
Menu1.Items[3].ImageUrl = "images/unselectedt4.jpg";
}
}
方法一结果截图
方法 2. 使用 javascript 和 css
aspx 代码
<asp:Menu
ID="Menu1"
runat="server"
Orientation="Horizontal"
StaticEnableDefaultPopOutImage="False"
OnMenuItemClick="Menu1_MenuItemClick" DynamicSelectedStyle-ForeColor="Black" StaticMenuItemStyle-Height="22px" StaticMenuItemStyle-Width="120px" StaticMenuItemStyle-ItemSpacing="2px" BackColor="#C3C3C3" Font-Size="16px" ForeColor="Black" Font-Names="cambria" StaticMenuItemStyle-VerticalPadding="3px" StaticMenuStyle-Width="900px" StaticSelectedStyle-BackColor="White" StaticSelectedStyle-ForeColor="Black" StaticMenuItemStyle-BorderColor="White" StaticMenuItemStyle-BorderWidth="2px">
<Items>
<asp:MenuItem Text="Building" Value="0"></asp:MenuItem>
<asp:MenuItem Text="Allocation" Value="2" ></asp:MenuItem>
<asp:MenuItem Text="Rent" Value="3" ></asp:MenuItem>
<asp:MenuItem Text="Kahramaa" Value="4" ></asp:MenuItem>
<asp:MenuItem Text="Owner" Value="5" ></asp:MenuItem>
<asp:MenuItem Text="Type" Value="6" ></asp:MenuItem>
</Items>
</asp:Menu>
javsascript 代码
<script src="Scripts/jquery-1.7.0.js" type="text/javascript"></script>
<script type ="text/javascript">
$(function () {
$("ul.level1 li").click(function () {
$(this).css("background-color:#ffffff;color:#000000;");
});
});
</script>
方法二结果截图