开发者

jquery focus to table

开发者 https://www.devze.com 2023-02-14 20:40 出处:网络
I wan开发者_Python百科t to bring focus to first row in a table when a page loads.I am using this for navigation

I wan开发者_Python百科t to bring focus to first row in a table when a page loads.I am using this for navigation in a table using key board.How do i bring focus and some times this keyboard navigation is also not working http://jsfiddle.net/hKZqS/8/ When using key board this is removing zebra stripes


Try the following jQuery code:

$(document).ready(function(){
    $("#myTable tbody tr").first().addClass("ui-selected");
});

// Do the clever keypress stuff
$(document).keyup( function(e)
{
    switch(e.which)
    {
        // user presses the "a" key
        case 38:
            if(!e.ctrlKey) {
                var selected = $("tr.ui-selected").first();
                if (selected.prev().html() != null) {
                    selected.prev().addClass("ui-selected");
                    selected.removeClass("ui-selected");
                }
            }
            break;    
        // user presses the "s" key
        case 40:  
            if(!e.ctrlKey) {
                var selected = $("tr.ui-selected").first();
                if (selected.next().html() != null) {
                    selected.next().addClass("ui-selected");
                    selected.removeClass("ui-selected");
                }
            }
            break;
    }
});

I tested it out and it seems to be working on a modified version of your jsFiddle: See Sample

0

精彩评论

暂无评论...
验证码 换一张
取 消