zoukankan      html  css  js  c++  java
  • 搜索关键字变色及高亮显示

    1.替换关键字,对字体变色。
            public static string ReplaceRed(string strtitle, string redkey)
            
    {
                
    if (redkey == "" || redkey == null)
                
    {
                    
    return strtitle;
                }

                
    else
                    strtitle 
    = strtitle.Replace(redkey, " <font color='#ff0000'>" + redkey + " </font>");
                
    return strtitle;
            }

    2.用正则,CSS背景变色。
            protected string HighlightText(string inputText,string searchWord)
            
    {
                System.Text.RegularExpressions.Regex expression 
    = new System.Text.RegularExpressions.Regex(searchWord.Replace(" ""|"), System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                
    return expression.Replace(inputText,new System.Text.RegularExpressions.MatchEvaluator(ReplaceKeywords));
            }

            
    public string ReplaceKeywords(System.Text.RegularExpressions.Match m)
            
    {
                
    return "<span class='highlightTxtSearch'>" + m.Value + "</span>";
            }

    CSS:
    .highlightTxtSearch
    {
        background-color
    :Yellow;
    }
  • 相关阅读:
    vs.net2003里添加邮件发件人身份验证
    Linux下用PYTHON查找同名进程
    修改机器名后要修改IIS匿名访问用户
    [C#]使用MYSQL数据库
    JIRA OutOfMemoryErrors
    获取linux下当机堆栈
    python调用pipe
    [探讨]一次性工具软件
    GGSN
    三层交换机的作用
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1230882.html
Copyright © 2011-2022 走看看