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;
    }
  • 相关阅读:
    tp5 -- 微信公众号支付
    tp5对接支付宝支付简单集成
    tp5 -- 腾讯云cos简单使用
    PHP 递归无限极下级
    PHP 头部utf-8
    ThinkPHP5.0-多语言切换
    MySQL插入SQL语句后在phpmyadmin中注释显示乱码
    C#中练级orcle数据查询
    sql中递归查询
    sql server数据类型与其他数据库数据类型对应关系
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1230882.html
Copyright © 2011-2022 走看看