如何编写代码来搜索特定单词的网站页面? [英] how do I write a code to search a website page for a specific word?
本文介绍了如何编写代码来搜索特定单词的网站页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写代码来搜索特定单词的网站页面?然后是控制台日志,我很新,我会尽可能多地获得帮助
谢谢
how do I write a code to search a website page for a specific word? then console log, I am pretty new and would appreciate as much help as I can get
Thank you
推荐答案
http://jsfiddle.net/z7fjW/134/ [ ^ ]
看看这个JsFiddle,希望这可能有所帮助你
http://jsfiddle.net/z7fjW/134/[^]
Check out this JsFiddle ,hope this may help you
试试这个代码..
try this code..
function searchAndHighlight(searchTerm, selector) {
if(searchTerm) {
//var wholeWordOnly = new RegExp("\\g"+searchTerm+"\\g","ig"); //matches whole word only
//var anyCharacter = new RegExp("\\g["+searchTerm+"]\\g","ig"); //matches any word with any of search chars characters
var selector = selector || "body"; //use body as selector if none provided
var searchTermRegEx = new RegExp(searchTerm,"ig");
var matches =
(selector).text()。match(searchTermRegEx);
if (匹配){
(selector).text().match(searchTermRegEx); if(matches) {
这篇关于如何编写代码来搜索特定单词的网站页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文