使用JavaScript/jQuery搜索关键字

use*_*756 6 javascript search jquery

我有一个静态网站,我想知道是否有可能在网站上有一个搜索表单,然后使用jQuery的JavaScript搜索页面中的某些关键字,然后使用jQuery添加一个类或其他东西.

Bry*_*llo 4

使用JQuery"Contains"选择器

然后使用addClass()方法分配您的类

  • http://api.jquery.com/addClass/

    <html>
    <head>
      <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>
    
    <div>John Resig</div>
    
    <div>George Martin</div>
    <div>Malcom John Sinclair</div>
    <div>J. Ohn</div>
    
    
    <script>
    $("div:contains('John')").css("text-decoration", "underline");
        </script>
    
    </body>
    </html>
    
    Run Code Online (Sandbox Code Playgroud)