获取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 >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值