2011-03-02 15 views
0

我想把焦點放在表格的第一行,當一個頁面加載。我使用這個導航 在一個表使用鍵盤board.How我帶來的焦點和有些時候這個鍵盤導航也是不工作 http://jsfiddle.net/hKZqS/8/當使用鍵盤,這是消除斑馬條紋jQuery的重點表格

回答

1

試試下面的jQuery代碼:

$(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; 
    } 
}); 

我測試了它,它似乎是工作在你的jsfiddle的修改版本:See Sample

+0

@FarlingOpptredon:當我使用jquery table sorter的這段代碼時,它不起作用[http://tablesoter.com/docs/] – pat 2011-03-02 13:03:35

+0

你能否分享一下你將它應用到jQuery table sorter的示例?請記住,我給出的這個示例根據您的原始示例查找ID爲「mytable」的表。更好的解決方案顯然是指定一個特定的CSS類,而不是一個ID。其餘的也依賴於CSS類。 – FarligOpptreden 2011-03-02 13:10:13

+0

FarligOpptreden:請參閱tablesorter鏈接。我只使用id。如何css classes.Can你可以修改你例如'我沒有指定selectme類。這是一個問題。 – pat 2011-03-02 13:23:24