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
精彩评论