JQuery实现搜索关键词变红,包含关键词的div显示,无div的隐藏
2016-12-30 09:30
603 查看
var arr2 = ""; var arr1 = ""; var x = ""; $(function() { $("#keywords").bind("input propertychange", function() { arr2 = $(this).val(); $("font").each(function() { var xx = $(this).html(); $(this).replaceWith(xx); }) if(/^[\u4e00-\u9fa5]+$/i.test(arr2)) { var reg = "/" + arr2 + "/g"; x = document.getElementsByClassName("qa_head"); for(var i = 0; i < x.length; i++) { arr1 = "<font class='fontRed'>" + arr2 + "</font>"; x[i].innerHTML = x[i].innerHTML.replace(eval(reg), arr1); } $("#rootpane .qa_head").hide(); $("#rootpane a:contains(" + arr2 + ")").parent().show(); } else { $("#rootpane .qa_head").show(); } }); })
<div class="keysearch"> <span>搜索城市:</span><input id="keywords" type="text" placeholder="请输入城市名称筛选" /> <div id="rootpane"> <div class="qa_head"> <a> <strong> 8:00起售车站</strong> 北京西、南京、南京南、同江。</a> </div> <div class="qa_head "> <a> <strong> 8:30 起售车站</strong>白城、成都东、东莞、东莞东、惠州、济宁、南充、宁波、日照、山海关、汕头、松原、乌兰浩特、乌鲁木齐南、南充北、乌鲁木齐。</a> </div></div>因发布在编辑器里面,所以代码有嵌套
附上实际演示地址http://www.green12306.com/informRead.htm?method=detail&checks=679
相关文章推荐
- Jquery/JS实现DIV的隐藏/显示
- jquery 实现背景图片循环切换,显示隐藏div
- JQuery实现DIV的显示与隐藏
- 基于jquery实现的定时显示与隐藏div广告的实现代码
- jquery和js实现对div的隐藏和显示方法
- jquery 实现定时显示与隐藏div广告代码
- jQuery基于闭包实现的显示与隐藏div功能示例
- jquery 实现点击其他地方隐藏之前点击显示的div标签等
- jQuery基于toggle实现click触发DIV的显示与隐藏问题分析
- 怎样用jquery实现点击一个按钮控制一个div的显示和隐藏
- 用jquery实现两个div的隐藏与显示
- 【jQuery】鼠标进入\离开操作实现div显示\隐藏
- jQuery点击按钮实现div的隐藏和显示切换效果
- 使用jquery点击一个实现button或连接,进行以下div显示,在点击隐藏
- jquery和js实现对div的隐藏和显示方法
- 基于jquery实现的定时显示与隐藏div广告的实现代码
- 使用jquery实现点击一个按钮或连接,让它下面的div显示,在点击一下隐藏
- jQuery实现动态搜索显示功能
- jQuery实现的可隐藏,显示的登陆框
- javascript实现div的显示和隐藏