2011-11-20 61 views
1

我想使用jQuery選項卡到表中的下一個單元格失敗,並相信這是由於我的選擇器中的錯誤。使用開發人員工具,我發現我的單元格是一個跨度,位於td .EditText中,位於<tr>內。這是我正在嘗試使用的代碼。使用jQuery選項卡到表中的下一個單元格

$(function() { 
    $('.EditText :text').live("keydown", function(e) { 
     if (e.which == 9) { //tab Key         
      $(this).blur(); 
      $(this).parent('tr').next('td #EditText').find('span').click(); 
      return false; 
     } 
    }); 
}); 

回答

2

我相信行:

$(this).parent('tr').next('td #EditText').find('span').click(); 

應該是:

$(this).next('td.EditText').find('span').focus(); 
1

這將是非常有用如果你能證明實際的標記,但我會採取刺吧:

// Replace this 
$(this).blur(); 
$(this).parent('tr').next('td #EditText').find('span').click(); 
// With this 
$(this).blur().closest('td').next().find('td .EditText span').focus(); 
0

我決定對此也採取行動。我爲這個人創建了一個jsfiddle,所以查看它並讓我知道它看起來是否正確。

這裏的果殼中的js我當前的例子:

$('table tr td.EditText span input').live('keydown', function(e) { 
    // get the code of the key that was pressed 
    var code = e.keyCode ? e.keyCode : e.which; 

    // varify that the tab key was pressed 
    if (code === 13) { 
     // get the next tr's input field, and set focus to it 
     $(this).parents('tr').next().find('td.EditText span input').focus(); 

     // prevent any default actions 
     if (e.preventDefault) { 
      e.preventDefault(); 
     } 
     return false; 
    } 
}); 
相關問題