简体   繁体   中英

How to capture menu selection events

I have to expand all collapsed rows of a table when user tries to search for a string using Ctrl + F or using menu item Find. I am able to do this when user hits Ctrl + F, but not sure how to achieve the same when user selects menu item Find.

$('body').keydown(function(e){
  if(e.ctrlKey && e.which == 70){
    $(expandAll());
  }
});

function expandAll() {
    $("#resultDetails tr").each(function(){
        if ($(this).hasClass('expand')) 
           $(this).removeClass('expand').addClass('collapse');
        $(this).show();
    });
}

Demo . How can I capture the browser menu item events.

Thoughts.

Just run the function like this:

$('body').keydown(function(e){
  if(e.ctrlKey && e.which == 70){
    expandAll(); //no need to use jQuery way
  }
});

As per your comment:

//run the function on click event:

$('.your-menu').on('click',expandAll);

There is NO way you can listen to browser events, the only thing you can do is the thing that you already did, subscribing to the keyup and keydown events only. You can NOT hook on the search browser function.

Use this javascript code no need to use any jquery

document.onkeydown = function (e) {

        // check ctrl + f key
        if (e.ctrlKey === true && e.keyCode === 70) {

            e.preventDefault();

           //alert('Ctrl + f was hit...');

             $(expandAll());

            return false;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM