是否可以使用 Jquery 模拟 Ctrl+F 组合键?

发布于 2024-12-03 19:57:08 字数 118 浏览 5 评论 0原文

我有一个包含大量信息的页面,如果用户单击链接并且弹出浏览器搜索栏,就像按下 Ctrl+ 一样,那就太好了F。我可以查询数据库,因为信息来自那里,但我不想在链接单击时重新加载页面。

I have a page with a lot of information in it, and it would be nice if the user clicked on a link and the the browser search bar popped out as it would if they pressed Ctrl+F. I could query the database, since the information cames from there, but I don't want to reload the page on link click.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烈酒灼喉 2024-12-10 19:57:08

某些浏览器支持 window.find()

Some browsers support window.find()

何处潇湘 2024-12-10 19:57:08

我知道这篇文章很旧,但我想我使用 jquery 解决了这个问题:

 //i am assuming you are searching through a table...
    //search input field listening for key pressed
    $('.search_input').keyup(function (e) {
        //listening if the key pressed is the enter button
        if (e.which === 13) {
            //inserting the value of textfield content, you can add if statement to check if the field is null or empty
            var search_param = $(this).val();
            //value of field stored into a variable
            $('tr').removeClass('item_found');
            //remove item_found class attributed to a td AND search all td to find the one that march the search parameter
            if ($('td:contains("' + search_param + '")').html() !== undefined) {
                //if there is any td that has that record... then check for the closest tr and add a class with item_found as value
                $('td:contains("' + search_param + '")').closest('tr').attr('class', 'item_found');
                //add some highlight to it.
                $('td:contains("' + search_param + '")').closest('tr').css({background:'yellow',color:'black'});
                //then scroll to the item
                $(window).scrollTop($('.item_found').first().offset().top);
            } else {
                //if item is not found display no result found
                alert("Sorry no result found")
            }
        }
    });

I know this post is old but i think i solved this using jquery:

 //i am assuming you are searching through a table...
    //search input field listening for key pressed
    $('.search_input').keyup(function (e) {
        //listening if the key pressed is the enter button
        if (e.which === 13) {
            //inserting the value of textfield content, you can add if statement to check if the field is null or empty
            var search_param = $(this).val();
            //value of field stored into a variable
            $('tr').removeClass('item_found');
            //remove item_found class attributed to a td AND search all td to find the one that march the search parameter
            if ($('td:contains("' + search_param + '")').html() !== undefined) {
                //if there is any td that has that record... then check for the closest tr and add a class with item_found as value
                $('td:contains("' + search_param + '")').closest('tr').attr('class', 'item_found');
                //add some highlight to it.
                $('td:contains("' + search_param + '")').closest('tr').css({background:'yellow',color:'black'});
                //then scroll to the item
                $(window).scrollTop($('.item_found').first().offset().top);
            } else {
                //if item is not found display no result found
                alert("Sorry no result found")
            }
        }
    });
莫多说 2024-12-10 19:57:08

有一些插件可以让您执行此操作,例如:https://github.com/jeresig/jquery。热键

There are some plugins that let you do this, for example: https://github.com/jeresig/jquery.hotkeys

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文