淘宝 网站建设教程,要对网页中各个元素,中小企业网站的主流类型是,淘宝联盟个人网站怎么做使用jQuery怎么实现一个页面关键字搜索功能发布时间#xff1a;2021-01-04 16:46:38来源#xff1a;亿速云阅读#xff1a;136作者#xff1a;Leah这篇文章给大家介绍使用jQuery怎么实现一个页面关键字搜索功能#xff0c;内容非常详细#xff0c;感兴趣的小伙伴们可以参…使用jQuery怎么实现一个页面关键字搜索功能发布时间2021-01-04 16:46:38来源亿速云阅读136作者Leah这篇文章给大家介绍使用jQuery怎么实现一个页面关键字搜索功能内容非常详细感兴趣的小伙伴们可以参考借鉴希望对大家能有所帮助。具体代码Searchp { border:1px solid black;width:500px;padding:5px;}.highlight { background-color:yellow; }I consider that a mans brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it.I consider that a mans brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it.I consider that a mans brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it.$(document).ready(function (){$(#search).click(highlight);//点击search时执行highlight函数$(#clear).click(clearSelection);//点击clear按钮时执行clearSelection函数function highlight(){clearSelection();//先清空一下上次高亮显示的内容var searchText $(#text).val();//获取你输入的关键字var regExp new RegExp(searchText, g);//创建正则表达式g表示全局的如果不用g则查找到第一个就不会继续向下查找了$(p).each(function()//遍历文章{var html $(this).html();var newHtml html.replace(regExp, searchText);//将找到的关键字替换加上highlight属性$(this).html(newHtml);//更新文章});}function clearSelection(){$(p).each(function()//遍历{$(this).find(.highlight).each(function()//找到所有highlight属性的元素{$(this).replaceWith($(this).html());//将他们的属性去掉});});}});关于使用jQuery怎么实现一个页面关键字搜索功能就分享到这里了希望以上内容可以对大家有一定的帮助可以学到更多知识。如果觉得文章不错可以把它分享出去让更多的人看到。