[英]Using JavaScript / jQuery to Search Keywords
我有一個靜態網站,我想知道是否有可能在網站上有一個搜索表單,然后使用jQuery的JavaScript搜索頁面中的某些關鍵字,然后使用jQuery添加一個類或其他東西。
使用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>
應該是可能的:
var text = $('body').html();
var split = text.split(/whatever/);
$('body').html(split[0] + '<span class="match">' + 'whatever' + '</span> + split[1]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.