English 中文(简体)
each each key
原标题:jquery keypress iterate through each loop?

hey guys, probably a simpel question, however couldn t find anything online.

i 有一个附有搜索结果的清单,希望能够用我手和 down钥匙通过清单。

    if (e.keyCode == 40) { //down
        //alert( down );
        $( #searchresults ul li ).each(function() { 

        });
    }

    if (e.keyCode == 38) { //up
        //alert( up );
    }

    if (e.keyCode == 13) { //enter
        //alert( enter );
    }

the searchresults look like this:

<ul>
    <li class="matched"><a href="link1">link1</a></li>
    <li class="matched"><a href="link2">link2</a></li>
    <li class="matched"><a href="link3">link3</a></li>
</ul>

因此,从根本上说,只是想通过我对钥匙的搜索结果而行走。 选择目前要素可能只是改变背景的颜色,而当媒体进入相关联和相应内容时。

any idea how i can iterate through the searchresults? thank you

编辑:

var pressedCount = 0;

if (e.keyCode == 40) { //down
    console.log(pressedCount);
    $( #searchresults ul li ).index(pressedCount).addClass( selected );
    pressedCount++;
}

这并不奏效,因为一米在指数方法上做过错。 然而,每一 trigger倒的触发点都引起压力。

最佳回答
问题回答

我不敢肯定,我真的喜欢把用户的钥匙拿走,特别是当我们生活在一个没有在很多关键板上出现上页/下台的世界时。 有许多用户使用arrow子进行滚动。

如果你在结果上坐在钥匙板上,就把注意力放在第一线上,那么塔夫将下台,什夫加布将接下去。

所有这些功能已经在你建立起来,只是必须把重点放在第一要素上。

$(首先_element_selector .focus();





相关问题
keyboard hook in windows C++ or what?

I wish to build my own application which can send keyboard commands(messages) to the Windows OS. For example when I press the combination ctrl+shift+n, I wish to launch the notepad.exe . How can I ...

Detect if any key is pressed in C# (not A, B, but any)

[EDIT 3] I kind of "solved it" by at using the "strange" version. At least for the most important keys. It is suffient for my case, where I want to check that ALT and ALT+A are not ...

Solution for iPhone new file dialog keyboard

i want to let the user type in the name of a new file, so there are certain characters i want to prevent entry on. is there a special keyboard i can use or can i disable certain keys on the iphones ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

热门标签