Home >Web Front-end >JS Tutorial >Two ways to implement javascript highlighting effect_javascript skills

Two ways to implement javascript highlighting effect_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:01:021122browse
js highlighting method one:
Copy code The code is as follows:

<script> <br>function HighLight(nWord){ <br><br>if(nWord!=''){ <br><br>var keyword = document.body.createTextRange(); <br><br>while(keyword.findText(nWord)){ <br><br>keyword.pasteHTML("<span style='color:red;'>" keyword.text "</span>"); <br><br>keyword.moveStart('character',1); <br><br>} <br><br>} <br><br>} <br><br>function highword(nWord){ <br><br>var array = nWord.split(","); <br><br>for(var i=0;i<array.length;i ){ <br><br>HighLight(array[i] ); <br><br>} <br><br>} <BR></script>




liujinzhong liujinzhong liuzhong






js highlighting method two:

2.
Copy code The code is as follows:

< html>

Test Page

< ;/head>


liujinzhong liujinzhong liuzhong




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn