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
最新文章
网页上的DIV, IFRAME标签, ActiveX控件之间互相覆盖的问题
SharePoint 2010在两个域是oneway trust的时候, 被trust域中的用户在搜索的时候得不到任何搜索结果
如何用编程方式实现创建一个页面并替换掉站点首页
如何在SharePoint 2010中开启Developer Dash Board?
如何禁用Office插件
SharePoint页面中显示PDF文件的问题
SharePoint 2007中的SSO概念基础
一些获取当前登录Windows系统用户信息的命令
安装更多域控制器的分步指南
CSS id 选择器
热门文章
在IIS中用ISAPI_Rewrite Lite版配置虚拟主机支持二级域名
SQL Server表分区操作详解
SQL Server 表分区(partitioned table/Data Partitioning)
数据库分区提高其性能并易于维护
VS2003远程调试
远程调试C# WinForm程序
CSS2 属性速查
配置 SQL Server 2005 远程调试存储过程
OnClientClick的window.confirm无效
mandrake安装INTEL e1000网卡驱动
Copyright © 2011-2022 走看看