我有一个静态网站,我想知道是否有可能在网站上有一个搜索表单,然后使用jQuery的JavaScript搜索页面中的某些关键字,然后使用jQuery添加一个类或其他东西。
use the JQuery "Contains" Selector
Then use the addClass() method to assign your class
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>
Should be possible:
var text = $('body').html();
var split = text.split(/whatever/);
$('body').html(split[0] + '<span class="match">' + 'whatever' + '</span> + split[1]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.