2014-09-02 103 views
0

我無法將焦點置於表格中輸入框的第一個td單元格。我使用this post的解決方案將單元格內容更改爲輸入。現在我想把焦點放在第一個輸入框上。 我的表結構是這樣的將焦點設置在第一個td單元格中,輸入表格

<table id="knowledgeTreeTable" class="custom"> 
    <tbody> 
    <tr> 
     <th class="">Who are the services being provided for?</th> 
     <td class=""> 
     <input type="text" style="width: 97%;"> 
     </td> 
    </tr> 
    <tr> 
    ..... 
    </tr> 
    ..... 
    </tbody> 
</table> 

回答

0

這?

$(document).ready(function(){ 
    $("#knowledgeTreeTable tr:nth-of-type(1) input").focus(); 
}); 

CSS僞類element:nth-of-type(n)選擇其在文檔中的類型的第n個元素。 由空格分隔的元素表示父子關係。因此,代碼說像

「選擇輸入,其父母爲它的類型的第一個,是一個元素的子ID爲knowledgeTreeTable

About pseudo-classes

0

Asumming你使用jQuery,你可以用這樣的東西:

$('#knowledgeTreeTable input').first().focus(); 
相關問題