我遇到一个奇怪的问题,我无法将样式表添加为选定项目:
我的HTML是这样的:
<asp:Menu ID="Menu2"
runat="server"
Orientation="Horizontal"
DisappearAfter="10"
CssClass="art-hmenu"
DataSourceID="XmlDataSource1"
IncludeStyleBlock="false"
StaticEnableDefaultPopOutImage="False">
<StaticSelectedStyle CssClass="selected"/>
<DataBindings>
<asp:MenuItemBinding DataMember="Item" NavigateUrlField="Url" TextField="Text" />
</DataBindings>
</asp:Menu>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" />
背后的代码是这样的:
public partial class Menu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SelectRighMenuItem();
}
}
/// <summary>
///
/// </summary>
void SelectRighMenuItem()
{
string appDataPath = HttpContext.Current.Server.MapPath("~/App_Data");
this.XmlDataSource1.DataFile = appDataPath + "\\" + GetRole() + "_menu.xml";
this.XmlDataSource1.XPath = @"/Items/Item";
}
protected string GetRole()
{
string role = string.Empty;
role = Session["Roles"].ToString();
return role;
}
}
我试过的是:
$(".art-hmenu>ul>li").on("click", "a", function (event) {
debugger;
$(this).addClass("selected");
});
但这不起作用!!
我也尝试设置StaticSelectedStyle !!但也没有用!
我使用的样式表是:
/* menu structure */
ul.art-hmenu a, ul.art-hmenu a:link, ul.art-hmenu a:visited, ul.art-hmenu a:hover {
outline: none;
position: relative;
z-index: 11;
}
.active {
color:green;
background-color:yellow;
}
ul.art-hmenu, ul.art-hmenu ul {
display: block;
margin: 0;
padding: 0;
border: 0;
list-style-type: none;
}
ul.art-hmenu li {
margin: 0;
padding: 0;
border: 0;
display: block;
float: left;
position: relative;
z-index: 5;
background: none;
}
ul.art-hmenu li:hover {
z-index: 10000;
white-space: normal;
}
ul.art-hmenu li li {
float: none;
width: auto;
}
ul.art-hmenu li:hover > ul {
visibility: visible;
top: 100%;
}
ul.art-hmenu li li:hover > ul {
top: 0;
left: 100%;
}
ul.art-hmenu:after, ul.art-hmenu ul:after {
content: ".";
height: 0;
display: block;
visibility: hidden;
overflow: hidden;
clear: both;
}
ul.art-hmenu, ul.art-hmenu ul {
min-height: 0;
}
ul.art-hmenu ul {
visibility: hidden;
position: absolute;
z-index: 10;
left: 0;
top: 0;
background-image: url('images/spacer.gif');
padding: 10px 30px 30px 30px;
margin: -10px 0 0 -30px;
}
ul.art-hmenu ul.art-hmenu-left-to-right {
right: auto;
left: 0;
margin: -10px 0 0 -30px;
}
ul.art-hmenu ul.art-hmenu-right-to-left {
left: auto;
right: 0;
margin: -10px -30px 0 0;
}
ul.art-hmenu ul ul {
padding: 30px 30px 30px 10px;
margin: -30px 0 0 -10px;
margin-left: -11px;
z-index: -1;
}
ul.art-hmenu ul ul.art-hmenu-left-to-right {
right: auto;
left: 0;
padding: 30px 30px 30px 10px;
margin: -30px 0 0 -10px;
margin-left: -11px;
}
ul.art-hmenu ul ul.art-hmenu-right-to-left {
left: auto;
right: 0;
padding: 30px 10px 30px 30px;
margin: -30px -10px 0 0;
margin-right: -11px;
}
ul.art-hmenu li li:hover > ul.art-hmenu-left-to-right {
right: auto;
left: 100%;
}
ul.art-hmenu li li:hover > ul.art-hmenu-right-to-left {
left: auto;
right: 100%;
}
ul.art-hmenu {
position: relative;
padding: 3px 3px 3px 3px;
float: left;
}
/* end menu structure */
/* menu bar */
.art-nav {
min-width: 700px;
max-width: 1728px;
margin: 0 auto;
min-height: 36px;
z-index: 100;
margin: 0 0 -36px;
width: auto;
top: 214px;
}
.art-nav:before, .art-nav:after {
background-image: url('images/nav.png');
}
.art-nav:before {
right: 0;
}
.art-nav:after {
width: 0;
}
/* end menu bar */
.art-nav-outer {
position: absolute;
width: 100%;
}
.art-nav-wrapper {
position: relative;
margin: 0 auto;
width: auto;
}
.art-nav-inner {
margin: 0 4px;
}
/* end Menu */
/* begin MenuItem */
ul.art-hmenu > li > a {
position: relative;
display: block;
height: 30px;
cursor: pointer;
text-decoration: none;
color: #D2E4EE;
padding: 0 20px;
line-height: 30px;
text-align: center;
}
ul.art-hmenu > li > a:before, ul.art-hmenu > li > a:after {
position: absolute;
display: block;
content: ' ';
top: 0;
bottom: 0;
z-index: -1;
background-image: url('images/menuitem.png');
}
ul.art-hmenu > li > a:before {
left: 0;
right: 12px;
background-position: top left;
}
ul.art-hmenu > li > a:after {
width: 12px;
right: 0;
background-position: top right;
}
.art-hmenu a, .art-hmenu a:link, .art-hmenu a:visited, .art-hmenu a:hover {
text-align: left;
text-decoration: none;
}
ul.art-hmenu > li > a.active:before {
background-position: bottom left;
}
ul.art-hmenu > li > a.active:after {
background-position: bottom right;
}
ul.art-hmenu > li > a.active {
color: #000000;
}
ul.art-hmenu > li > a:hover:before, ul.art-hmenu > li:hover > a:before {
background-position: center left;
}
ul.art-hmenu > li > a:hover:after, ul.art-hmenu > li:hover > a:after {
background-position: center right;
}
ul.art-hmenu > li > a:hover, ul.art-hmenu > li:hover > a {
color: #D9E0E8;
}
/* end MenuItem */
/* begin MenuSeparator */
ul.art-hmenu > li:before {
position: absolute;
display: block;
content: ' ';
top: 0;
left: -13px;
width: 13px;
height: 30px;
background: url('images/menuseparator.png') center center no-repeat;
}
ul.art-hmenu > li {
margin-left: 13px;
}
ul.art-hmenu > li:first-child {
margin-left: 0;
}
ul.art-hmenu > li:first-child:before {
display: none;
}
/* end MenuSeparator */
/* begin MenuSubItem */
.art-hmenu ul a {
display: block;
white-space: nowrap;
height: 24px;
background-image: url('images/subitem.png');
background-position: left top;
background-repeat: repeat-x;
border-width: 1px;
border-style: solid;
border-top-width: 0;
border-color: #99ADC2;
min-width: 7em;
text-align: left;
text-decoration: none;
line-height: 24px;
color: #152B38;
margin: 0;
padding: 0 8px;
}
.art-hmenu ul > li:first-child > a {
border-top-width: 1px;
}
.art-hmenu ul a:link , .art-hmenu ul a:visited, .art-hmenu ul a:hover, .art-hmenu ul a:active {
text-align: left;
text-decoration: none;
line-height: 24px;
color: #152B38;
margin: 0;
padding: 0 8px;
}
.art-hmenu ul a:link .highlighted {
color: #152B38;
background-color: #fff;
}
.art-hmenu ul li a:hover {
color: #000000;
background-position: left bottom;
border-color: #A76801;
border-top-width: 1px !important;
}
.art-hmenu ul li a.art-hmenu-before-hovered {
border-bottom-width: 0 !important;
}
.art-hmenu ul li:hover > a {
color: #000000;
background-position: left bottom;
border-color: #A76801;
border-top-width: 1px !important;
}
.art-hmenu ul li:hover > a.selected
{
color: #000000;
background-position: left bottom;
border-color: #A76801;
border-top-width: 1px !important;
}
.SelectedMenuItem
{
color: #000000;
background-position: left bottom;
border-color: #A76801;
border-top-width: 1px !important;
}
/* end MenuSubItem */