I have following html:

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

How can I set the focus on this input field in table row "myid" with jquery ? I can't set id on input field, because this html was generated automatically.

有帮助吗?

解决方案

Use the table as an anchor and find the input regardless of its value.

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

其他提示

Selecting the field as-is:

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

Or if there's a chance that there will be more than one input with that value:

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

If it's the ID you need to focus on, use that in your selector:

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

more jQuery selectors

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top