在网站上搜索文本 [英] Searching the text on website

查看:38
本文介绍了在网站上搜索文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的会员,

我在一个模板的帮助下用纯 HTML 设计网站.

I am designing the website in pure HTML with the help of one Template.

因为我有一个文本框[search] 和 Go 按钮.

In that i have one textbox[search] and Go button.

我想进行这样的操作,当任何人输入某些文本并按下 Go 按钮时,它应该突出显示该网站中与该文本匹配的文本.

I want to make operation such that when any one types certain text and presses Go button, It should highlight the text in that website which is matching to that text.

我该怎么做?

比你.

推荐答案

$(document).ready(function(){
        $('#searchItem').keyup(function(){
            var name = $(this).val();
            var pattern = name.toLowerCase(); 
            var targetId = ""; 
            var divs = document.getElementsByClassName("item"); 

            $(document).find('.item').hide();

            $('.item').each(function(i){
                var para = divs[i].getElementsByTagName("p"); 
                var index = para[0].innerText.toLowerCase().indexOf(pattern); 
                if (index != -1) { 
                    $(this).show();
                }
            });
        }); 
    });

这篇关于在网站上搜索文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆