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

men*_*ici 7 javascript browser jquery keyboard-shortcuts

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

epa*_*llo 6

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

  • 这似乎是要走的路.我刚刚在FF,Chrome和IE9中测试过它. (2认同)

小智 5

我知道这篇文章很旧,但我想我使用 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")
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)