var Html= ' ddfsdfsdfdsd dfsdfsdffdsdfsdfsrewewrererew dsdfsdfsdfsddfsddfdsdfd; String.prototype.replaceAll=function(S1,S2) {return This. replace (NewREGEXP (S1, "GM"), S2);}varAppendhtml= "";varKeyword= "S";varPartarray=html.split ("<"); $.each (Partarray,function(key,value) {//Console.log ("value=" +value+ "; key=" +key); varSecpartarray=value.split (' > ')); $.each (Secpartarray,function(key1,value1) {if(Value1.indexof ("img") ==0) {appendhtml+ = "<" +value1+ ">"; } Else{appendhtml+=value1.replaceall (keyword, "<strong>" +value1+ "</strong>"); } console.log (value1); });}); Console.log (appendhtml);
This idea and method can be used to highlight the contents of the text, the IMG tag contains content can not be replaced by errors.
How to use JS script to detach picture labels and text from HTML, replace specified content in text and Bold (original)