• 获取url的文件名(动态改变css)


     /// <summary>
        
    ///Css 的摘要说明
        
    /// </summary>
        public class Css
        {
            
    string cssAStr = "";
            
    string cssBStr = "";
            
    string defaultCssStr = "";

            
    /// <summary>
            
    /// 样式切换函数
            
    /// </summary>
            
    /// <param name="cssA"></param>
            
    /// <param name="cssB"></param>
            
    /// <param name="defaultCss"></param>
            public Css(string cssA, string cssB, string defaultCss)
            {
                cssAStr 
    = cssA;
                cssBStr 
    = cssB;
                defaultCssStr 
    = defaultCss;
            }

            
    /// <summary>
            
    /// 样式切换函数
            
    /// </summary>
            
    /// <param name="cssA"></param>
            
    /// <param name="cssB"></param>
            public Css(string cssA, string cssB)
            {
                cssAStr 
    = cssA;
                cssBStr 
    = cssB;
                defaultCssStr 
    = "";
            }

            
    /// <summary>
            
    /// 获取匹配样式
            
    /// </summary>
            
    /// <param name="value">标准值</param>
            
    /// <param name="key">比较值</param>
            
    /// <returns>筛选字符串</returns>
            public string GetCssStr(string value, string key)
            {
                
    string returnValue = "";
                List
    <string> valueList = new List<string>();
                List
    <string> keyList = new List<string>();
                
    foreach (string s in value.Split(new char[] { '|' }))
                {
                    valueList.Add(s.ToLower());
                }
                
    bool flag = false;
                
    foreach (string s in key.Split(new char[] { '|' }))
                {
                    
    if (valueList.Contains(s.ToLower()))
                    {
                        flag 
    = true;
                        
    break;
                    }
                }

                
    if (flag)
                {
                    returnValue 
    = cssAStr;
                    
    // HttpContext.Current.Response.Write(cssAStr);
                }
                
    else
                {
                    returnValue 
    = cssBStr;
                    
    //HttpContext.Current.Response.Write(cssBStr);
                }
                
    return returnValue;
            }

            
    /// <summary>
            
    /// 获文件名
            
    /// </summary>
            
    /// <returns>获取文件名</returns>
            public string GetFileName()
            {
                
    return System.IO.Path.GetFileName(HttpContext.Current.Request.PhysicalPath);
            }

            
    /// <summary>
            
    /// 获取不带扩展名的文件名
            
    /// </summary>
            
    /// <returns>获取文件名(不需要扩展名)</returns>
            public string GetFileNameWithoutExt()
            {
                
    return System.IO.Path.GetFileName(HttpContext.Current.Request.PhysicalPath).Split('.')[0];
            }
        }

    在  masterpage中初始化   protected Css itemCss = new Css("class=\"liston\"", "");

      <ul>
                            
    <li <%=itemCss.GetCssStr("MyCart",itemCss.GetFileNameWithoutExt())%> onmouseover="this.className='liston'"
                                onmouseout
    ="this.className='listoff'">
                                
    <a href="MyCart.aspx">
                                    
    <img src="../themes/user/img/list.gif" hspace="20" />我的购物车</a></li>
                            
    <li <%=itemCss.GetCssStr("OrderAll|OrderConfirm|ProductComment|CompanyComment|Comment",itemCss.GetFileNameWithoutExt())%>
                                onmouseover
    ="this.className='liston'" onmouseout="this.className='listoff'">
                                
    <a href="OrderAll.aspx">
                                    
    <img src="../themes/user/img/list.gif" hspace="20" />我的订单</a></li>
                            
    <li <%=itemCss.GetCssStr("MyCart",itemCss.GetFileNameWithoutExt())%> onmouseover="this.className='liston'"
                                onmouseout
    ="this.className='listoff'">
                                
    <a href="temporary.aspx">
                                    
    <img src="../themes/user/img/list.gif" hspace="20" />暂存架</a></li>
                            
    <li <%=itemCss.GetCssStr("ShopCollection",itemCss.GetFileNameWithoutExt())%> onmouseover="this.className='liston'"
                                onmouseout
    ="this.className='listoff'">
                                
    <a href="ShopCollection.aspx">
                                    
    <img src="../themes/user/img/list.gif" hspace="20" />商家收藏</a></li>
                            
    <li <%=itemCss.GetCssStr("MyCommentContent|MyCompanyComment|MyProductComment",itemCss.GetFileNameWithoutExt())%>
                                onmouseover
    ="this.className='liston'" onmouseout="this.className='listoff'">
                                
    <a href="MyProductComment.aspx">
                                    
    <img src="../themes/user/img/list.gif" hspace="20" />我的评论</a></li>
                        
    </ul>
  • 相关阅读:
    实验9: 静态路由和默认路由
    实验8:路由器IOS升级2
    实验7:交换机IOS升级
    实验6:路由器IOS升级
    实验5: IOS的升级与恢复
    实验4: 路由器的密码恢复
    实验3: DHCP 基本配置
    Linux用户的基本操作3 (组的基本管理,用户提权)
    拓展练习:(用户的基本管理及用户提权部分)
    linux用户的基本操作2 用户密码管理
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1452771.html
Copyright © 2020-2023  润新知