diff --git a/static/mrdoc/mrdoc-docs.js b/static/mrdoc/mrdoc-docs.js index 121a3da..34e051b 100644 --- a/static/mrdoc/mrdoc-docs.js +++ b/static/mrdoc/mrdoc-docs.js @@ -357,24 +357,26 @@ textBecomeImg = function(text,fontsize,fontcolor){ // 搜索词高亮 function keyLight(id, key, bgColor){ // console.log(id,key,decodeURI(key)) - key = decodeURI(key); - var oDiv = document.getElementById(id), - sText = oDiv.innerHTML, - bgColor = bgColor || "#c00", - sKey = ""+key+"", - num = -1, - rStr = new RegExp(key, "ig"), - rHtml = new RegExp("\<.*?\>","ig"), //匹配html元素 - aHtml = sText.match(rHtml); //存放html元素的数组 - sText = sText.replace(rHtml, '{~}'); //替换html标签 - // sText = sText.replace(rStr,sKey); //替换key - sText = sText.replace(rStr,function(text){ - return ""+text+"" - }); //替换key - sText = sText.replace(/{~}/g,function(){ //恢复html标签 - num++; - return aHtml[num]; - }); - oDiv.innerHTML = sText; + if(key != false){ + key = decodeURI(key); + var oDiv = document.getElementById(id), + sText = oDiv.innerHTML, + bgColor = bgColor || "#c00", + sKey = ""+key+"", + num = -1, + rStr = new RegExp(key, "ig"), + rHtml = new RegExp("\<.*?\>","ig"), //匹配html元素 + aHtml = sText.match(rHtml); //存放html元素的数组 + sText = sText.replace(rHtml, '{~}'); //替换html标签 + // sText = sText.replace(rStr,sKey); //替换key + sText = sText.replace(rStr,function(text){ + return ""+text+"" + }); //替换key + sText = sText.replace(/{~}/g,function(){ //恢复html标签 + num++; + return aHtml[num]; + }); + oDiv.innerHTML = sText; + } }; keyLight('doc-content',getQueryVariable("highlight")) \ No newline at end of file