2013-08-19 110 views
0

的jquery我有以下的html:將焦點設置輸入字段與特定的錶行

<table> 
    .... 
    <tr> 
    .... 
    </tr> 
    .... 
    <tr id="myid"> 
    <....> 
     <input value="..." /> 
    </....> 
    </tr> 
    <tr id="myanotherid"> 
    <....> 
     <input value="..." /> 
    </....> 
    </tr> 
</table> 

我怎樣才能將焦點設置在錶行「身份識別碼」與jQuery此輸入字段?我無法在輸入字段上設置id,因爲這個html是自動生成的。

+0

它不應該有一個名字嗎? – Blazemonger

+0

這是我的問題,這個html是automaticaly生成的。 –

回答

1

將該表用作錨點並查找輸入,而不管其值如何。

$('table tr#myid').find('input:first').focus() 
+1

'$('table tr#myid')'是不必要的; $('#myid')'就足夠了。 – Blazemonger

2

選擇字段-是:

$('input[value="abc"]').focus(); 

或者,如果有一個機會,將有與該值超過一個input

$('input[value="abc"]:first').focus(); 

如果這是你需要關注的ID在你的選擇器上使用:

$('#myid input:first').focus(); 

more jQuery selectors

+0

謝謝你的回答!我更新了我的問題。 –

相關問題