2011-11-20 59 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; 
    } 
}); 
相关问题