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

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
T
Tailwind CSS Blog
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
Webroot Blog
Webroot Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Cloudflare Blog
T
Threat Research - Cisco Blogs
V
Visual Studio Blog
Jina AI
Jina AI
V
V2EX
I
InfoQ
Latest news
Latest news
P
Proofpoint News Feed
T
Threatpost
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
美团技术团队
The Register - Security
The Register - Security
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
Cloudbric
Cloudbric
Microsoft Azure Blog
Microsoft Azure Blog
C
Cisco Blogs
U
Unit 42
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
W
WeLiveSecurity
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
小众软件
小众软件
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
N
News and Events Feed by Topic

博客园 - 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------------------------

在线演示