簡體   English   中英

使用 Jquery 聚焦<tr><td>

[英]focus Using Jquery <tr> <td>

$(this).closest('tr').next() td:eq(7).focus();

這有什么錯誤? 我是 jQuery 的新手。 如何使用trtdtable index 集中注意力?

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

語法不太對。 您可以使用以下任一方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM