zoukankan      html  css  js  c++  java
  • web 开发之js---js 实现文本高亮

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>文字高亮</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script language="javascript">
    function init() {

    var keys = new Array("aa", "bb", "cc");

    var keysOther = new Array("11", "22", "33");

    var reblog = eval("/("+keys.join('|')+")/gi");

    document.getElementById("title").innerHTML = document.getElementById("title").innerHTML.replace(reblog,"<font color=red>$1</font>");
    document.getElementById("summary").innerHTML = document.getElementById("summary").innerHTML.replace(reblog,"<font color=red>$1</font>");

    var reblogOther = eval("/("+keysOther.join('|')+")/gi");

    document.getElementById("title").innerHTML = document.getElementById("title").innerHTML.replace(reblogOther,"<font color=yellow>$1</font>");
    document.getElementById("summary").innerHTML = document.getElementById("summary").innerHTML.replace(reblogOther,"<font color=yellow>$1</font>");
    }



    </script>

    </head>

    <body>
    <button onclick="init()">xxxxxxx</button>
    <table width="100%" height="100%">
    <tr>
    <td id="title">
    asdasdflsajdfaafdsfjbbfdsffecc11sdfsssscc22222sdfs333
    </td>
    </tr>
    <tr>
    <td id="summary">
    asdasdflsajdfaafdsfjbbfdsffecc11sdfsssscc22222sdfs333
    </td>
    </tr>
    </table>
    </body>
    </html>

    http://blog.csdn.net/whumr1/article/details/6760746

  • 相关阅读:
    HDU 6071
    HDU 6073
    HDU 2124 Repair the Wall(贪心)
    HDU 2037 今年暑假不AC(贪心)
    HDU 1257 最少拦截系统(贪心)
    HDU 1789 Doing Homework again(贪心)
    HDU 1009 FatMouse' Trade(贪心)
    HDU 2216 Game III(BFS)
    HDU 1509 Windows Message Queue(队列)
    HDU 1081 To The Max(动态规划)
  • 原文地址:https://www.cnblogs.com/pengkunfan/p/4040374.html
Copyright © 2011-2022 走看看