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

推荐订阅源

L
LINUX DO - 最新话题
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Securelist
V2EX - 技术
V2EX - 技术
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy & Cybersecurity Law Blog
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
H
Heimdal Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Recorded Future
Recorded Future
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
量子位
V
V2EX
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Vercel News
Vercel News
H
Help Net Security
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
T
Threatpost
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
T
Threat Research - Cisco Blogs
人人都是产品经理
人人都是产品经理
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
罗磊的独立博客
C
Check Point Blog
P
Palo Alto Networks Blog
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
A
Arctic Wolf

博客园 - cncxz(虫虫)

在.NET环境下为网站增加IP过滤功能 推荐几个基于.net的cms系统 超赞的10个Windows Live Writer插件 发布ASP.NET应用程序时的10个好习惯(转) 一个基于web的pdf浏览器 ajax跨域访问代理文件下载(asp、php、asp.net) jQuery UI 1.0 已于2007-9-16日正式发布 Visual Studio插件大搜索(60+) 推荐一批基于web的开源html文本编辑器(40+) 终结IE6下背景图片闪烁问题 一个web应用程序统计在线用户列表的东东(带c#源码) 中了网络流氓www.e-jok.cn的招 Div+Css酷站一箩筐 在win2k3上使用卡巴斯基6.0 发布控件Express.NET.WindowsForms运行时的本地化补丁 创建为ClickOnce清单签名的.pfx格式数字证书 Windows Live Messenger去广告补丁 一个阴历阳历互相转化的类(c#源码) 小发现:sql2005中的异常处理消息框可以直接使用
使用 javascript 标记高亮关键词
cncxz(虫虫) · 2007-07-15 · via 博客园 - cncxz(虫虫)

一个将指定html标签内特定关键词高亮显示的javascript 函数。


    
/*----------------------------------------*\ 
     * 使用 js 标记高亮关键词 by markcxz(markcxz@aol.com)
     * 参数说明: 
     * obj: 对象, 要进行高亮显示的html标签节点. 
     * hlWords: 字符串, 要进行高亮的关键词词, 使用 竖杠(|)或空格 分隔多个词 . 
     * cssClass: 字符串, 定义关键词突出显示风格的css伪类. 
     * 参考资料: javascript HTML DOM 高亮显示页面特定字词 By shawl.qiu
    \*----------------------------------------
*/ 
    
function MarkHighLight(obj,hlWords,cssClass){
    
        hlWords
=AnalyzeHighLightWords(hlWords);
        
        
if(obj==null || hlWords.length==0)
            
return;
        
if(cssClass==null)
            cssClass
="highlight";
        MarkHighLightCore(obj,hlWords);
        
        
//------------执行高亮标记的核心方法----------------------------
        function MarkHighLightCore(obj,keyWords){
            
var re=new RegExp(keyWords, "i"); 
            
            
for(var i=0; i<obj.childNodes.length; i++){
            
                
var childObj=obj.childNodes[i];
                
if(childObj.nodeType==3){
                    
if(childObj.data.search(re)==-1)continue
                    
var reResult=new RegExp("("+keyWords+")""gi"); 
                    
var objResult=document.createElement("span");
                    objResult.innerHTML
=childObj.data.replace(reResult,"<span class='"+cssClass+"'>$1</span>");                     
                    
if(childObj.data==objResult.childNodes[0].innerHTML) continue
                    obj.replaceChild(objResult,childObj);                                      
                }
else if(childObj.nodeType==1){
                    MarkHighLightCore(childObj,keyWords);
                }
            }
        }        
//----------分析关键词----------------------
        function AnalyzeHighLightWords(hlWords)
        {
            
if(hlWords==nullreturn "";
            hlWords
=hlWords.replace(/\s+/g,"|").replace(/\|+/g,"|");            
            hlWords
=hlWords.replace(/(^\|*)|(\|*$)/g, "");
            
            
if(hlWords.length==0return "";
            
var wordsArr=hlWords.split("|"); 
            
            
if(wordsArr.length>1){
                
var resultArr=BubbleSort(wordsArr);
                
var result="";
                
for(var i=0;i<resultArr.length;i++){
                    result
=result+"|"+resultArr[i];
                }                
                
return result.replace(/(^\|*)|(\|*$)/g, "");

            }

else{
                
return hlWords;
            } 
        }    
        
        
//-----利用冒泡排序法把长的关键词放前面-----    
        function BubbleSort(arr){        
            
var temp, exchange;    
            
for(var i=0;i<arr.length;i++){            
                exchange
=false;                
                
for(var j=arr.length-2;j>=i;j--){                
                    
if((arr[j+1].length)>(arr[j]).length){                    
                        temp
=arr[j+1]; arr[j+1]=arr[j]; arr[j]=temp;
                        exchange
=true;
                    }
                }                
                
if(!exchange)break;
            }
            
return arr;            
        }
    
    }
    
//----------------end------------------------

在线演示