0

NOTE:

I believe I found my solution, sorry for the long post: I use "focusout" on the last href in the last li. seems to work so far.

 var lastLi = jQuery("#items").find('li:last');
 jQuery(lastLi).last('a').focusout(function(eve){
    // close em'
 });

So, I am creating some code to tab thru a CSS menu. As such, I need to be aware of persons who use tab to go thru menu items. I have things working pretty good EXCEPT when they leave the last link (last LI in code below) and move to the next nav item (Link that Might exist). The menu sticks (stays open). I could just as easily put a keyup on that link and just close the previous menus, BUT because the site is dynamic, those "other links" might not exist so I can't really plan for what link follows the .

I was hoping to do a

jQuery('#itemsForSale').bind('blur', function() {//close menu})

no luck.

So here is a snippet of the code.

<ul id='siteNavigation'>
    <li id="itemsForSale">
       <div id="items">
          <ul id='itemNav'>
             <li>
                 <div id="menu1">
                    <ul>
                       <li>menu 1 item 1</li>
                       <li>menu 1 item 2</li>
                    </ul>
                 </div>
             </li>
             <li>
                  <div id="menu2">
                    <ul>
                       <li>menu 2 item 1</li>
                       <li>menu 2 item 2</li>
                    </ul>
                 </div>
             </li>
          </ul>
       </div>
    </li>
    <li>Link that Might exist</li>
    <li>AnotherLink that Might exist</li>
</ul>

So, because the last two li's might or might not be there, I am trying to capture the "blur" event on id "itemsForSale" - no luck. There doesn't seem to be a "keyout" event. Is there a way to know via tabing when I exit this particular li id="menu 2 item 2" OR the parent li id="itemsForSale"?

Mind you, I have pretty much all of the other tabbing etc.. working just fine. But WHen the user gets to that last item (in my case above: menu 2 item 2 ) and moves off of it, how to know that.

I also tried capturing the "last LI" in "itemsForSale" - that was also a no go. Blur just doens't seem to work. I also tried using a setTimeout with it, nada. Any advice?

Note: Remember, I have to make this determination with a keypress of tab or "shift tab".

jQuery("#items").find('li:last')
4

1 回答 1

0

您可以查看focus事件,然后他们确定刚刚获得焦点的元素是否是菜单的子元素?

于 2013-01-25T07:20:57.733 回答