2016-04-20 78 views
1
$(this).closest('tr').next() td:eq(7).focus(); 

这是什么错误?我是jQuery的新手。我如何使用trtdtable索引进行对焦?focus使用jquery <tr>​​

$('.gridfield').keypress(function(e) { 
    console.log(this); 
    if (e.which == 13) {  
     var row_index = $(this).parent().index();  
     $(this).closest('tr').next() td:eq(row_index).focus();  
     e.preventDefault(); 
    } 
}); 
+3

'$(本).closest( 'TR')的next()找到( 'TD')当量(ROW_INDEX).focus(); ' –

+0

没有工作......对于这个......的任何其他解决方案? – Bipin

+0

你想做什么?分享你需要的html样本 –

回答

1

语法不太正确。您可以使用此:

$(this).closest('tr').next().find('td').eq(row_index).focus();  

或者这样:

$(this).closest('tr').next().find('td:eq(' + row_index + ')').focus();  

它们在逻辑上是相同的。

每个细胞都包含输入字段

在这种情况下使用的两者之一:。

$(this).closest('tr').next().find('td').eq(row_index).find('input').focus(); 
$(this).closest('tr').next().find('td:eq(' + row_index + ') input').focus(); 
+0

没有聚焦...... – Bipin

+0

好吧,你不会看到聚焦'td'的任何明显效果,我认为你有一个事件挂钩它。你想要做什么? –

+0

我正在寻找MS Excel中的事件。例如:当我按下Enter按钮时,courser向下移动1个单元格,当我按下箭头键时,向上,向下,向左和向右移动。和MS Excel一样。 – Bipin