惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
U
Unit 42
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Secure Thoughts
Hacker News: Ask HN
Hacker News: Ask HN
Vercel News
Vercel News
S
Security @ Cisco Blogs
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
I
Intezer
MongoDB | Blog
MongoDB | Blog
AI
AI
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
博客园 - 叶小钗
S
SegmentFault 最新的问题
N
News | PayPal Newsroom
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
H
Help Net Security
美团技术团队
博客园 - 司徒正美
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity
J
Java Code Geeks
量子位
Martin Fowler
Martin Fowler
博客园_首页

博客园 - Sherrys

Content-Type 参数 Sql 2000 中行转列的查询方法 DotNet Framework 小技巧 通过 INotifyPropertyChanged 实现观察者模式 使用 .NET 2.0 SecureString 类保护敏感数据 API参数说明符前缀详解 C#中调用Windows API的要点 - Sherrys - 博客园 SQL 处理简单的 Xml Special Considerations When Using Query Notifications 利用.NET Framework使用RSS feed SQL远程连接 SQL 事务的隔离 SELECT 语句收藏(2000 & 2005) 自动处理 SQL 2005 表格数据 SQL事务的使用 查询SQL连接数的方法 对象的继承方案 使用 ICallbackEventHandler aspx页面中的DropDownList 的 SelectValue 出现中文导致不回调方法的问题 如何利用SQL Server 2005数据库快照形成报表
用JS让文章内容指定的关键字加亮 - Sherrys - 博客园
Sherrys · 2007-02-25 · via 博客园 - Sherrys

单关键词

<div id="txt">
用JS让文章内容指定的关键字加亮

小楼昨夜又春风,云雨巫山数落红。

花径不曾缘客扫,蓬门今次为君开。

</div>
<script language="JavaScript">

txt.innerHTML = txt.innerHTML.replace(/文章/gi,"<font color=red>文章</font>");

</script>

多关键词

<div id="txt">
用JS让文章内容指定的关键字加亮

舍南舍北皆春水,但见群鸥日日来。

花径不曾缘客扫,蓬门今始为君开。

盘餐市远无兼味,樽酒家贫只旧醅。

肯与邻翁相对饮,隔篱呼取尽余杯。

</div>
<script language="JavaScript">

txt.innerHTML = txt.innerHTML.replace(/(文章)|(日)|(花)/gi,"<font color=red>$1$2$3</font>"); 

</script>

关于Code的说明

字符 含义
$$ $ (JScript 5.5 或更新版本)
$& 指定与整个模式匹配的 stringObj 的部分。 (JScript 5.5 或更新版本)
$` 指定由 $& 描述的匹配之前的 stringObj 部分。 (JScript 5.5 或更新版本)
$' 指定由 $& 描述的匹配之后的 stringObj 部分。 (JScript 5.5 或更新版本)
$n 捕获的第 n 个子匹配,此处 n 为从1到9的十进制一位数。 (JScript 5.5 或更新版本)
$nn 捕获的第 nn 个子匹配,此处 nn 为从01到99的十进制两位数。 (JScript 5.5 或更新版本)
g,全局模式匹配
i,不区分大小写匹配

从文本入手,改变文字的颜色

<pre>
用JS让文章内容指定的关键字加亮

事了拂衣去,深藏功与名。

谁能书阁下,白首太玄经。


</pre>

<script language="JavaScript">
function highlight(key)
{
var key = key.split('|');
for (var i=0; i<key.length; i++)
{
var rng = document.body.createTextRange();
while (rng.findText(key[i]))
rng.pasteHTML(rng.text.fontcolor('red'));
}
}
highlight('文章|下|白首'')
</script>