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;
    }
  • 相关阅读:
    Struts2的HelloWorld
    javaScript 避免使用eval
    javaScript 全局变量注意
    NET下的XML序列化 5
    通过aps.net创建web services 3
    XML web Service标准2
    webServices简介笔记1
    批量更新
    物理数据模型(PDM)->概念数据模型 (CDM)->面向对象模型 (OOM):适用于已经设计好数据库表结构了。
    json时间格式的互换
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1230882.html
Copyright © 2011-2022 走看看